- Home /
Need a menu to pop up
Hey, I know this is a stupid question but I was wondering how to make it so that say if I click the spacebar a menu appears.
Answer by Peter G · Apr 19, 2010 at 12:18 AM
It is really simple. Here's a simple code to make a box appear and disappear when the user hits the space button.
private var active1 = false;
function OnGUI () { if(Input.GetButtonDown("Jump")) { active1 = active1 ? false : true; //if true make it false and vice-versa. //let's the user toggle it on and off. }
if (active1) { //only display the box if the user hit space.
GUI.Box(/*Rect, "Pop up box", style*/);
}
}
What do you mean? Are you talking about this line? active1 = active1 ? false : true; That's a conditional operator that says if active1 is true, make it false and if it is false make it true. It just saves the space of writing "if(active{active = false; } else if (!active) {active = true;}"
You put this script on whatever object controls your GUI. Then you put the pop up window where it says GUI.Box();
Your answer
Follow this Question
Related Questions
Need help with sprite animating 1 Answer
Menu Animation 2 Answers
Menu Script Problem 0 Answers
RTS building placement with reference while placing buildings 3 Answers