GUI help

hmm, I’ve given up on the last menu, but would like to leave the thread for learning purposes. Will check for responses. Since I’ve taken a crack at GUI programming.

I plan on doing a cut scene on the main menu, but no matter what I do my GUI buttons show up. I’ve even tried hiding the GUI function inside a function that gets called on a bool, but still… They keep showing up, lol…

#pragma strict

var ButtonHeight = 50;
var ButtonWidth = 200;
var Spacing = 25;
var ShowMenuButtons = false;


function ShowMenuButtons(){

	function OnGUI(){


	GUILayout.BeginArea(Rect(Screen.width/2 - ButtonWidth/2, Screen.height /2 - 200, ButtonWidth, 400));

		if (GUILayout.Button("New Game", GUILayout.Height(ButtonHeight))){
					
					Application.LoadLevel("Level1");

		
		}
		
	GUILayout.Space(Spacing);
	
		if (GUILayout.Button("Load Game", GUILayout.Height(ButtonHeight))){
		
			/* Load Game Code Goes Here. */
		
		
		}
		
	GUILayout.Space(Spacing);
	
	if (GUILayout.Button("Exit Game", GUILayout.Height(ButtonHeight))){
	
		Application.Quit();
	
	}

	GUILayout.EndArea();

}

}


}

if (ShowMenuButtons){

	function ShowMenuButtons();

}





function Start () {

}

function Update () {

}

hmm. I just learned that you can fire methods within animations. Since this is for the main menu that’s perfect. The problem is I can’t stop my gui from showing all the time. Even if I hide it in a user defined method. I cleaned up the code a bit, but it’s still not working…

#pragma strict

var ButtonHeight = 50;
var ButtonWidth = 200;
var Spacing = 25;


function ShowMenuButtons(){

	function OnGUI(){


	GUILayout.BeginArea(Rect(Screen.width/2 - ButtonWidth/2, Screen.height /2 - 200, ButtonWidth, 400));

		if (GUILayout.Button("New Game", GUILayout.Height(ButtonHeight))){
					
					Application.LoadLevel("Level1");

		
		}
		
	GUILayout.Space(Spacing);
	
		if (GUILayout.Button("Load Game", GUILayout.Height(ButtonHeight))){
		
			/* Load Game Code Goes Here. */
		
		
		}
		
	GUILayout.Space(Spacing);
	
	if (GUILayout.Button("Exit Game", GUILayout.Height(ButtonHeight))){
	
		Application.Quit();
	
	}

	GUILayout.EndArea();

}


}




function Start () {

}

function Update () {


}

Sorry for posting so much but I found another persons answer to this problem, and it gave me an idea. I buried the Gui two levels deep. Once inside a user defined function and once in an if statement inside OnGUI() Still the darn thing shows…

#pragma strict

var ButtonHeight = 50;
var ButtonWidth = 200;
var Spacing = 25;
private var ShowGui = false;

function ShowMenuButtons(){


	function OnGUI(){
	
		if (ShowGui){


	GUILayout.BeginArea(Rect(Screen.width/2 - ButtonWidth/2, Screen.height /2 - 200, ButtonWidth, 400));

		if (GUILayout.Button("New Game", GUILayout.Height(ButtonHeight))){
					
					Application.LoadLevel("Level1");

		
		}
		
	GUILayout.Space(Spacing);
	
		if (GUILayout.Button("Load Game", GUILayout.Height(ButtonHeight))){
		
			/* Load Game Code Goes Here. */
		
		
		}
		
	GUILayout.Space(Spacing);
	
	if (GUILayout.Button("Exit Game", GUILayout.Height(ButtonHeight))){
	
		Application.Quit();
	
	}

	GUILayout.EndArea();

}
}


}




function Start () {

}

function Update () {


}

Amazing how tough this is… lol.

OnGUI() is called every frame so putting that function inside another is weird.

Instead put your GUI code in a function that is called from OnGUI and then then in the OnGUI check if the value of the bool before calling the function.

Look at the console in my signature. should help.

Hey, thanks guys… fixed :slight_smile: