Hi all I was hoping someone would be able to help me. I have a script in c# for OnMouseDown to pick up a key, picking up said key creates a sound and destroys it. I want to make it so that the door I need the key for is locked and cannot be opened at all, but once I pick up the key the door unlocks and I can interact with the door (which has it’s own separate script). Could someone show me how I would do this please? I believe it has something to do with a global script but that is why I am here Thank you for any help in advance.
If needed the script I have for my key is:
public class KeyPickup : MonoBehaviour
{
public GUIText KeyHover;
public AudioClip keygrab;
void OnMouseOver()
{
KeyHover.text = "The key for the door at Reception";
}
void OnMouseExit()
{
KeyHover.text = null;
}
void OnMouseDown()
{
StartCoroutine("KeyPickUp");
audio.enabled = true;
light.enabled = false;
}
IEnumerator KeyPickUp()
{
Debug.Log ("Picked up key");
renderer.enabled = false;
collider.enabled = false;
yield return new WaitForSeconds (3f);
}
}