these are my key and door codes. if you look at my key codes there is Door.keyfound = true; but it doesnt affect the keyfound variable in my door code. idk why can someone explain
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class keyScript : MonoBehaviour
{
public GameObject presstoequip, key;
void OnTriggerStay(Collider other)
{
if (other.CompareTag("MainCamera"))
{
presstoequip.SetActive(true);
if (Input.GetKey(KeyCode.F))
{
key.SetActive(false);
Door.keyfound = true;
presstoequip.SetActive(false);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("MainCamera"))
{
presstoequip.SetActive(false);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public GameObject door_closed, door_opened, intText, lockedtext, crosshair;
public AudioSource open, close;
public bool opened, locked;
public static bool keyfound;
void Start()
{
keyfound = false;
}
void OnTriggerStay(Collider other)
{
if (other.CompareTag("MainCamera"))
{
if (opened == false){
if(locked == false)
{
intText.SetActive(true);
if (Input.GetKey(KeyCode.E))
{
door_closed.SetActive(false);
door_opened.SetActive(true);
intText.SetActive(false);
//open.Play();
StartCoroutine(repeat());
opened = true;
}
}
if (locked == true)
{
lockedtext.SetActive(true);
crosshair.SetActive(false);
}
}
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("MainCamera"))
{
intText.SetActive(false);
lockedtext.SetActive(false);
crosshair.SetActive(true) ;
}
}
IEnumerator repeat()
{
yield return new WaitForSeconds(3.0f);
opened = false;
door_closed.SetActive(true);
door_opened.SetActive(false);
//close.play();
}
void update()
{
if (keyfound == true)
{
locked = false;
}
}
}