I am trying to make a menu screen with only GUI buttons. I wrote this code and I was wondering what was wrong with it because as soon as I start the game it shows the menu for about 1 second and then it loads the first level. And in the menu the button for the options menu is there also.
var options : boolean = false;
var menu : boolean = true;
function Start ()
{
menu = true;
options = false;
}
function OnGUI ()
{
if (menu == true);
{
Debug.Log("Menu is TRUE");
if(GUI.Button (Rect (Screen.width/2, Screen.height/2 + 10, 100, 25), "Start Game"));
{
Debug.Log("Game Started");
Application.LoadLevel("Level 1");
}
if(GUI.Button (Rect (Screen.width/2, Screen.height/2, 100, 25), "Options"));
{
Debug.Log("Options Menu activated");
menu = false;
options = true;
}
if(GUI.Button (Rect (Screen.width/2, Screen.height/2 - 20, 100, 25), "Quit Game"));
{
Debug.Log("Game Quit");
Application.Quit();
}
}
if (options == true);
{
Debug.Log("Options is TRUE");
if(GUI.Button (Rect (Screen.width/2, Screen.height/2 - 50, 100, 25),"Back"));
{
menu = true;
options = false;
}
}
}
Edit: Updated script
I just attached this to the camera for the scene. Anything i’m doing wrong?
Heres a screenshot of the menu for the short time it is shown:
