I'm trying to get a script going that will perform different functions based off of the buttons you press. The eventual end result will be; when you click on a door to go to the next scene, it will pop up a box confirming that you'd like to go. If you click yes, It will Load the next level, if you click no, it will simply turn the GUI back off until you click the door again.
I'm trying it out on a box (it should yield the same results in the end game) If you click "yes", it destroys the box... that part works... however, I can't figure out what to do to make "no" turn the GUI off.
function OnGUI()
{
GUI.Box(Rect(100,100,300,100),"Would You Like To Destroy This Box?");
if(GUI.Button(Rect (100,150,100,25),"Yes"))
{
Destroy (gameObject);
}
if(GUI.Button(Rect(300,150,100,25),"No"))
{
//What Goes Here?
}
}
I think what you want is, to not display anything until a box/door is clicked (rather than disabling the GameObject entirely). Consider re-writing it like this:
var showChoice : Boolean;
function Start() {
showChoice = false;
}
function OnGUI()
{
if (showChoice == false)
return;
GUI.Box(Rect(100,100,300,100),"Would You Like To Destroy This Box?");
if(GUI.Button(Rect (100,150,100,25),"Yes"))
{
Destroy (gameObject);
}
if(GUI.Button(Rect(300,150,100,25),"No"))
{
showChoice = false;
}
}
function OnMouseUp() {
showChoice = true;
}