Displaying Text On touch

Hey, In my game I have traps that are basically just boxes and I am trying to figure out how to display GUI text when my player touches it. At the moment I have this:

var endMessage : GUIText;

function OnCollisionEnter (col : Collision) {
    endMessage.text = "On No... You Died, Try Again";
    Application.LoadLevel(1);
}

And I can't seem to fix it... If anyone has a working script on a tip that would be great. Thanks

Well assuming everything's set up right, and you are hitting the trigger, you're probably not giving it enough time to display the message before loading a level.

Try putting a `yield;` between the endMessage.text and the Application.LoadLevel. Try putting some text on the GUIText by default to see if it actually shows up on screen. Here are some other debugging tips.

Without knowing how your scene, GUIText, trigger, etc. are set up it's hard to know why it isn't working.

I'm not using Javascript but I've done something similar in c#. Create a GameObject and add a GUIText to it. Then write a script like this. Note that the c# code is just a "short version"

public static bool on; // switch the messages on and off
public static string text;  //text to be displayed
GUIText messages // this will hold the GUIText component, to access its text

void Start()
{
    messages=(GUIText)GetComponent("GUIText");
}
void Update()
{
    if(on)
    {
        messages.enabled=true;
        messages.text=text;
    }
    else
    {
        messages.enabled=false;
    }
}

Now you can access the GUI messages by adjusting the static variables of your script. Let's assume you named your script "texthints". Then the following should work:

void OnCollisionEnter (Collision col) 
{
    texthints.text = "On No... You Died, Try Again";
    texthints.on=true
    Application.LoadLevel(1);
}