Hello,
I am working on a script which when you do not have a key a bool is false. But when you have the key the bool is true. Basically when I pick the key up the bool won’t change from false to true and I’m not too sure why, Here’s my script:
using UnityEngine;
public class Door : MonoBehaviour
{
public GameObject key;
public Animator ANI2;
public GameObject Text;
public AudioSource dooropen;
public AudioSource doorlock;
public bool haskey;
public bool Dooropen;
void Start()
{
haskey = false;
}
void OnTriggerStay(Collider other)
{
Text.gameObject.SetActive(true);
if (Input.GetKeyDown("e"))
{
ANI2.enabled = true;
ANI2.SetInteger("Doorani", 1);
Dooropen = false;
if (haskey == true)
{
dooropen.Play();
}
}
if (Input.GetKeyUp("e"))
{
ANI2.enabled = false;
}
if (haskey == true)
{
Dooropen = true;
ANI2.SetInteger("Doorani", 2);
}
if (haskey == false)
{
Dooropen = false;
ANI2.SetInteger("Doorani", 1);
}
}
void OnTriggerExit(Collider other)
{
Text.gameObject.SetActive(false);
ANI2.enabled = false;
}
void Update()
{
if (ANI2.enabled == true)
{
Text.gameObject.SetActive(false);
}
if (Dooropen == true)
{
Text.gameObject.SetActive(false);
}
if (key == false)
{
haskey = true;
}
if (key == true)
{
haskey = false;
}
}
}