Text on Trigger

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());
        }
    }
}

Could be something to do with thisTrigger not being Set Active? I see you change it to inactive during your coroutine but not vice versa on trigger enter

If ‘thistrigger’ is the same game object, the rest of the coroutine won’t finish.

Just to check, in addition, are the Text and Image game objects already active before you active (enable) the Text and Image? Those are just components that you enable, but if the whole game object is inactive still, that won’t show it.

1 Like

Ive fixed it, but thank you :slight_smile:

Cool.