- Home /
how to instantiate a GUI text box for end of game...help?
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); }
Answer by Sebas · Feb 17, 2010 at 12:32 AM
Since you mention an invisible box, I would probably use a Trigger instead of a Collider. Set your box collider to isTrigger and try the following script (attach to the box).
You have a boolean variable which determines whether the trigger has been entered. If this variable is true, it will display the win-message within the OnGUI function. You can also add more stuff below the win-message like advance to a new level, etc.
private var triggerEnd : boolean;
function OnTriggerEnter (other : Collider) {
triggerEnd = true;
}
function OnGUI () {
if (triggerEnd == true) {
GUI.Box(Rect (10, 10, 100, 20), "Hello World!");
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A trigger is activating scripts of other triggers 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
How Activating a boolean fron another script(C#) 1 Answer
Setting Scroll View Width GUILayout 1 Answer