trying to instantiate a GUI text box and having trouble

this is the script i put on the empty game object with a box collider so that when the spaceship(which also has a box collider) hits collides with the invisible box collider it should make a GUI text box appear saying “You Win!”…but it’s not working…I’m guessing I probably should have a OnGUI function somewhere but I’m not sure where…I’m new to this whole Unityscripting thing…

// A spaceship // - instantiates a GUI text box declaring your a winner when hitting a invisible box collider var GameEnd : GUI.box(Rect (10,10,100,100),“You Win!”);

function OnCollisionEnter(collision : Collision) { Instantiate(GameEnd); }

You may also want to get used to this forumthingy too, as your question has already been answered in your previous identical post here:
http://forum.unity3d.com/viewtopic.php?t=44052

GUI elements aren’t game objects, and consequently can’t be instantiated. Try using a boolean variable to store whether or not your ship has collided, and only show the text box when that value is true.

var finishedGame = false;

function OnCollisionEnter (collision : Collision) {
	finishedGame = true;
}

function OnGUI () {
	if (finishedGame) {
		GUI.Box(Rect(10, 10, 100, 100), "You Win!");
	}
}

And yes, GUI elements have to be contained in the OnGUI function.

I don’t want to be harsh but I have to agree with this, especially as you started that other thread and received at least one reply before starting this one. Please do not double-post or re-post the same question over and over as that only adds clutter to the forums.

I’m going to lock this thread, all conversation on this topic can occur in the OP’s original thread to be found here:

GUI box wont show