I've Messed up Somewhere, Please help me

I’ve apparently called a guiText.text that hasn’t been attatched to the object I’m using it for, but the only problem is that I don’t know where I can attatch it to or how to do so.

I’ll be more specific, because none of the methods below have worked for what I’m trying to do. I’m trying to make it that when you collide with a specific object, “You win!” is painted on the screen for an amount of time before the game ends. I attatched a guiText to the player now in order to get it to be displayed. But now when I collide with the object, nothing happens. This is my code`#pragma strict

function OnTriggerEnter (other : Collider) {
guiText.text = “You win!”;
Application.Quit();
}

function Update () {

}`
Again, I have the guiText attatched to the player, and this code is attached to the object that you are supposed to win when you collide with it.

If you’ve just specified it as guiText.text, then you are specifying any GUIText components attached to the gameObject that the script is assigned to. To attach a GUIText component to that gameObject, go to Components > Rendering > GUIText.

Else if you’re referencing a GUIText component attached to another gameObject, first declare a variable which references said gameObject like so:

var guiTextObject : GameObject;

And then declare your its GUIText component like this:

guiTextObject.guiText.text

Make sure to assign the object reference in the Inspector. And then you’re good to go! :stuck_out_tongue:

Hope that helps, Klep