Hello, I’m making an indie horror game and i used this code to make the text appear when a player enters the collider and disappears when the player leaves it. it worked at first but as i progressed with making the game is stopped working, now the text shows up when i enter the collider but doesn’t disappear when I leave it. Any help would be appreciated! here’s my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Textlol : MonoBehaviour {
public string text;
bool display = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update() { }
void OnTriggerEnter(Collider iCollide)
{
if (iCollide.transform.name == "Player")
{
display = true;
}
}
void OnTriggerExit(Collider uCollide)
{
if (uCollide.transform.name == "player")
{
display = false;
}
if (display == false)
{
Destroy(gameObject);
}
}
void OnGUI()
{
if (display ==true)
{
GUI.Box(new Rect(0, Screen.height / 1.21f, Screen.width / 1f, Screen.height / 19.58f), text);
}
else
{
Destroy(gameObject);
}
}
}