Hi guys! I wrote script for opening doors, when player has got a key. It works fine, but only if i set bool “HasKey” in inspector.
I want to get this value “HasKey = true;”, when player pick ups the key. I don’t know what to do with it.
Scripts:
Door locked script:
using UnityEngine;
using System.Collections;
public class DoorLocked : MonoBehaviour {
public bool HasKey = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay()
{
if(HasKey == false)
{
if(Input.GetKey(KeyCode.F))
{
GameObject.Find("DoorLockedNapis").GetComponent<GUIText>().enabled = true;
StartCoroutine("NapisLocked");
}
}
else
{
if(Input.GetKey(KeyCode.F))
{
animation.Play();
}
}
}
IEnumerator NapisLocked()
{
yield return new WaitForSeconds(3);
GameObject.Find("DoorLockedNapis").GetComponent<GUIText>().enabled = false;
}
}
Pickup script:
using UnityEngine;
using System.Collections;
public class KeyPickup : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay()
{
if(Input.GetKey(KeyCode.F))
{
GameObject.Find("Key").GetComponent<MeshRenderer>().enabled = false;
}
}
}
Thanks for help ![]()