- Home /
Simple Menu(understanding GUI)
I am simply trying to make a small menu that appears for a quit and return to game sequence. I'm not sure what I'm doing wrong.. but I'd like it if I could have some help fixing or understanding why nothing appears :) I currently have it attached to an invisible game object that the camera follows along.
> function Update () {
> if(Input.GetKeyDown(KeyCode.Escape))
> { menuButtons();
>
> } }
>
>
> function menuButtons(){ var
> labelOptions = GUILayout.Width(90);
> GUI.Button(Rect(25,25,100,30),"Quit");
>
> if(GUILayout.Button("Quit")) {
> Application.Quit(); } }
Answer by Griffo · Oct 26, 2012 at 06:17 AM
Try this.
var escPressed : boolean;
function Update () {
if(Input.GetKeyDown("esc")){
escPressed = true;
}
}
function OnGUI(){
if(escPressed == true){
labelOptions = GUILayout.Width(90);
GUI.Button(Rect(25,25,100,30),"Quit");
}
}
Answer by FearThisTeam · Oct 26, 2012 at 12:02 AM
You need an OnGUI function I think. The way I do this is with booleans, it may not be quite right but try this out:
var escPressed : boolean;
function Start(){
escPressed = false;
}
function Update () {
if(Input.GetKeyDown("esc")){
escPressed = true;
}else{
escPressed = false;
}
}
function OnGUI(){
if(escPressed == true){
labelOptions = GUILayout.Width(90);
GUI.Button(Rect(25,25,100,30),"Quit");
}
}
hmm. that seemed to have done the trick, but when I hit escape it just flashes and goes away Really fast.
Your answer
Follow this Question
Related Questions
Gui Login With Interface 1 Answer
Simple menu 1 Answer
Individually rotate GUI Elements? 4 Answers
How to make a menu that looks like a smartphone/tablet? 2 Answers