I am trying to make a door that opens and closes but when you press E on it the intText sets to false but nothing happens to the door_closed and door_opened. The code looks fine to me so why isnt it working? The script is on the parent of door_closed and door_opened.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public GameObject door_closed, door_opened, intText, lockedtext;
public AudioSource open, close;
public bool opened, locked;
public static bool keyfound;
private void Start()
{
keyfound = false;
opened = false;
}
private 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);
opened = true;
}
}
if (locked == true)
{
lockedtext.SetActive(true);
}
}
if (opened == true)
{
if (locked == false)
{
intText.SetActive(true);
if (Input.GetKey(KeyCode.E))
{
door_closed.SetActive(true);
door_opened.SetActive(false);
intText.SetActive(false);
opened = false;
}
}
if (locked == true)
{
lockedtext.SetActive(true);
}
}
}
}
private void OnTriggerExit(Collider other)
{
if(other.CompareTag("MainCamera"))
{
intText.SetActive(false);
lockedtext.SetActive(false);
}
}