My script for displaying text when the player enters a trigger isn’t working, and I can’t figure out why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextOnTrigger : MonoBehaviour
{
public Text gtext;
public string message;
public Image gimage;
public GameObject thistrigger;
IEnumerator wait()
{
thistrigger.SetActive(false);
yield return new WaitForSeconds(7);
gimage.enabled = false;
gtext.enabled = false;
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
gtext.text = message;
gtext.enabled = true;
gimage.enabled = true;
StartCoroutine(wait());
}
}
}