Character Collision Trigger Text Message Help!

Hey guys, I am new to scripting and do not know how to go about creating this. That said, I want a text message to show up when my character walk’s thru a collider and as he exit’s out, the text should disappear. And apart from this, how can I make the text disappear after a certain amount of time?

Well, this is what I’ve done so far. Now the text appears after a certain interval and does not disappear. Would be really nice If someone could help me out. Thank you very much in advance.

using UnityEngine;
using System.Collections;
 
public class mainText : MonoBehaviour 
{
    public float letterPause = 0.05f;
    public AudioClip sound;
    public GUIStyle font;
    string message;
    string text;
 
 
    void Start () 
    {
       message = "Hello, World!";
       StartCoroutine(TypeText());
    }
 
    IEnumerator TypeText () 
    {
        float timeToWait = 2; 
 
         float incrementToRemove  = 0.5f;
 
         while(timeToWait > 0)
 
 
     {
 
          yield return new WaitForSeconds(incrementToRemove ); 
 
          timeToWait -= incrementToRemove;
 
     }
 
       foreach (char letter in message.ToCharArray()) 
       {
         text += letter;
         if (sound)
          audio.PlayOneShot (sound);
          yield return 0;
         yield return new WaitForSeconds (letterPause);
       }      
    }
 
    void OnGUI()
    {
       GUI.Label(new Rect(0, 0, 256, 1024), text, font); 
    }
 
    void Update()
    {
       if(Input.GetKeyDown (KeyCode.Return))
       {
         StopAllCoroutines();
         text = message;
       }
    }
}

If you want the text to appear/disappear when the character enters/exits a trigger collider, you can use OnTriggerEnter and OnTriggerExit (virtual methods of the MonoBehaviour class). To limit this behaviour to one trigger in particular, check the trigger name before performing any text-related behaviour.

// This is Unity Javascript, not C#, but you get the idea
function OnTriggerEnter (other:Collider) {
   if (other.name == "textTrigger"){
      // Display text
   }
}

Hope that helps.

Thank you so much. I figured it out!