I'm attempting to allow the players to open the door once they have located the key The 'hasKey' value is currently managing if the players has the key with either true or false. i now need to know how to use this 'hasKey' boolean in another script; i've been trying for hours and getting no where so i'll post my code below and maybe someone knows whats going on, thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Detection : MonoBehaviour {
public GameObject objectToEnable;
public static bool Enabled = false;
public bool hasKey = false;
public DoorOpener _DoorOpener;
private void Update()
{
Debug.Log(hasKey);
if (Enabled)
{
objectToEnable.SetActive(true);
}
}
void OnMouseEnter()
{
Debug.Log("Enter");
}
void OnMouseExit()
{
Debug.Log("Exit");
}
void OnMouseUp()
{
Enabled = true;
hasKey = true;
Debug.Log("Pressed");
}
}
public class DoorOpener : MonoBehaviour
{
Animator animator;
bool JailDoorOpen;
public Detection _Detection;
void Start()
{
JailDoorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerEnter(Collider JailDoorO)
{
if ((JailDoorO.gameObject.tag == "Player") && (_Detection.hasKey == true))
{
Debug.Log("Open Door");
JailDoorOpen = true;
jDoors("Open");
}
}
void jDoors (string direction)
{
animator.SetTrigger(direction);
}
}
enter code here