Help In Creating GUI Start Menu

Hello, what I’m trying to wonder is how do I make a Start Menu that behaves like one. We know what they are like, you click on the “New Game” button and a box appears on what game slot you would like to save and such. What I’m trying to do, is make this happen. By simply clicking on button which then draws the texture of the GUI 2D thing. Here’s my code.

var newGame : Texture2D;
var loadGame : Texture2D;
var options : Texture2D;
var skirmish : Texture2D;
var multiplayer : Texture2D;
var quitGame : Texture2D;

var newGameTemplate : Texture2D;
/*var loadGameTemplate : Texture2D;
var optionTemplate : Texture2D;
var skirmishTemplate : Texture2D;
var multiplayTemplate : Texture2D;
var quitGameTemplate : Texture2D;*/

function OnGUI()
{
	if (GUI.Button(Rect(13,80,250,50), "")) //New Game Button
	{
	
	}
	
	if (GUI.Button(Rect(18,190,250,50), "")) // Button Load Game
	{
	}
	
	if (GUI.Button(Rect(13,308,195,50), "")) //Button Options
	{
	}
	
	if (GUI.Button(Rect(16,420,200,50), "")) //Button Skirmish
	{
	}
	
	if (GUI.Button(Rect(13,515,310,50), "")) //Button Multiplayer
	{
	}
	
	if (GUI.Button(Rect(10,620,260,30), "")) //Button Quit
	{
		Application.Quit();
	}
}

The Buttons fit over my set of Textures if your wondering why I have the comments laid out as it is. So I’ll say this again to be clear. What would be the code if the GUI button gets hit?.
I was thinking, I have already tried this I think if not similar.
In between the

if (GUI.Button(Rect(13,80,250,50), "")) //New Game Button
	{
	     GUI.DrawTexture(newGameTemplate);
	}

But of course there has to be a “Rect” to make a Rectangle around it and a position… I’m tired seeing errors and wasting time trying to make a simple Start Menu. If you have any idea on what I’m rambling about, then please help me.

var gui:GUITexture;

function Update () {
var NewVector:Vector2 = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
     if(TouchForGUITest(gui,NewVector)==true){
        //do something
     }
}

function TouchForGUITest(object : GUIElement, touch : Vector2) : boolean { 
    var rect = object.GetScreenRect(camera);
    if(rect.Contains(touch)){ 
        return true; 
    }
    else{
        return false; 
    }
}

that works for me anyway

i attach it to any game object i want to be a menu button and simply attach the texture and the whole texture becomes the button.

i then apply what ever function i want to run inside the update.

in your case it would be something like

var targetLevel:int = 1;

function StartGame(){
      Application.LoadLevel(targetLevel)
}

you will also have to make sure every level is loaded into your build settings.

not sure if that helps with your question though.

There are a many ways to do it depending on what your going for. are you trying to get the texture you draw to be a button or just a splash screen(ie credits pop up or game info). What i would do in this sit would be to enable a GUITexture(to be visible)and then with another button disable it so it toggles the GUITexture.

var guiTexture1 : GUITexture;
//GUI function here
//Your button here
for( var g in guiTexture1)
g.enabled = true;
//next button here
for( var g in guiTexture1)
g.enabled = false;

The best way i have found is to have your gui code in a sizable begin and end flexable area. so that when someone changes the screen resolution to you game the gui components will resiz too.

If you want to enable or disable a whole new gui script(make more buttons appear)there are a couple of ways to do that too. One is to enable or disable the whole script.

var scriptOn1 : MonoBehaviour[];
///////////////////////
for(var s in scriptOn1)
s.enabled = false;//Or true ofc

And another way is to create a if condition right inside your main menu gui function with a bool. :smile: