[4.6 JS] How to show GUI text on a trigger enter and then take it away on exit?

I’m doing a kind of level choice scene (like Mario) and I want it to show GUI text (like the name of the level) when the player enters an invisible trigger. Now, this would be easy but since 4.6 it is not as easy as just putting it in a GUI.Label or something (otherwise if you can still do that, please remind me how to then). I’m not really amazing at coding, and everything I have found has been really confusing and hasn’t worked (e.g instantiate). Why isn’t it so simple anymore? Please just help me show GUI text in a trigger!

To use Triggers you would use unity’s functions of

OnTriggerEnter()
OnTriggerExit()
OnTriggerStay()

to use this make sure one of the objects has a rigidbody2D (assuming its 2D colliders becaus said mario like) and to remove physics tick the IsKinematic (if you dont want them)

and make sure that there are boxColliders2D on each object with IsTrigger Selected

The Least cody looking way of doing it is to add this script to the level object that you wish to show its name, make a new c# script and call it SomeScript

using UnityEngine;
using System.Collections;

public class SomeScript : MonoBehaviour {

    //this will tell us if the player
    // has enter or has exit the collider
	private bool showName = false;
	
	//this is a unity function that fires 
    // when this 2dCollider enters another collider
	void OnTriggerEnter2D()
	{
            //we know that the player has just enterd 
            // the collider so we want to show name
		showName = true;
	}

    //this is unity function that fires when
    // this collider exits another collider
	void OnTriggerExit2D()
	{
            //we know the player has left the
            // collider so we dont want to show name
		showName =false;
	}

    //OnGUI is a unity function that will let us use GUI elements
	void OnGUI()
	{   
            //if showName is true then show the lable
		if(showName)
            {
                    //this creats a lable in top left corner and will
                    // display the name of the object from the hierarchy
			GUI.Label(new Rect(10,10,100,100), transform.name);
            }
	}
	
}

now drop it onto your level object,

now when your char enters it will show the name of your level object at the top and when you leave it will go away.

this is the same code as above but with no comments

using UnityEngine;
using System.Collections;

public class SomeScript : MonoBehaviour {
	
	private bool showName = false;
	
	void OnTriggerEnter2D()
	{
		showName = true;
	}
	void OnTriggerExit2D()
	{
		showName =false;
	}
	
	void OnGUI()
	{
		if(showName)
			GUI.Label(new Rect(10,10,100,100), transform.name);
	}
	
}