I am making a game that involves finding objects around the environment. So far I made it so that the name of the object appears when the player approaches it, but now I need to make it so that the text disappears once the player has exited the collider. Here is my code for the object; how can I fix it to make this addition?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextTrigger : MonoBehaviour
{
public Text keycardText;
private bool closeEnough = false;
void Start()
{
closeEnough = false;
keycardText.text = " ";
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Player")
{
closeEnough = true;
keycardText.text = "Keycard";
}
}
}
Thank you!