x


How to make a Main Menu GUI

How do you make a Main Menu for a FPS using the GUI to select other options like a level and other settings, and what is the script for you to do that?

more ▼

asked Feb 26, 2010 at 05:21 AM

Trevor 1 gravatar image

Trevor 1
61 22 21 28

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

You can find all basic GUI controls here : http://unity3d.com/support/documentation/Components/gui-Controls.html

You can use a combination of Toolbar , Window and Button elements to create Menus using GUI

more ▼

answered Feb 26, 2010 at 06:04 AM

jitesh gravatar image

jitesh
101 6 4 9

(comments are locked)
10|3000 characters needed characters left

Well you make the main menu just like any other GUI. And there is no specific script, it varies from game to game.

I'll give you something to start you off

var windowRect = Rect (20, 20, 120, 50);
 Function OnGUI()
{
windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
}

Function DoMyWindow(windowID : Int)
{
if (GUI.Button (Rect (10,20,100,20), "Quit"))
Application.Quit;
}

Thats pretty much the start of it. You'll have to really edit this though and add what you need, but thats the basic stuff.

more ▼

answered Feb 26, 2010 at 06:04 AM

Will gravatar image

Will
423 20 17 29

Some main menus are made as the first scene.

Feb 26, 2010 at 01:23 PM Motionreactor
(comments are locked)
10|3000 characters needed characters left

I hope this will help you:

function Start(){
    GUI.skin = MyGUI.getSkin();
    areaWidth = MyGUI.getAreaWidth();
    screenX = MyGUI.getScreenX();
    screenY = MyGUI.getScreenY();
}

function OnGUI(){

    var sizeOuter   = Rect (Screen.width - areaWidth - ScreenX , ScreenY, areaWidth, Screen.height - ScreenY*2);
    var sizeInner   = Rect (Screen.width - areaWidth, ScreenY*2+30, areaWidth - ScreenX*2, Screen.height - ScreenY*4);

    GUI.Box(sizeOuter, "Administration Interface");

    GUILayout.BeginArea (sizeInner);
        if (ServiceInterface.userIsLoggedIn()){
            MyGUI.showLogout();
        } else {
            MyGUI.showLogin();
        }
        if (ServiceInterface.userIsRegistered()) 
            MyGUI.showUserInterfaces();
        if (ServiceInterface.userIsAdmin()) 
            MyGUI.showAdminInterfaces();
    GUILayout.EndArea();
} 

And somewhere else I have:

class MyGUI{
    function showLogin(){
        var labelOptions =GUILayout.Width(90);
        GUILayout.BeginHorizontal();
            GUILayout.Label("Username:",labelOptions); 
            userName = GUILayout.TextField (userName, 25);
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
            GUILayout.Label("Password:",labelOptions); 
            passwordName = GUILayout.PasswordField (passwordName, "*"[0], 25);
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
            GUILayout.Label("");
            if(GUILayout.Button("Login"))
            {
                ServiceInterface.runLogin(userName,passwordName);
            }
        GUILayout.EndHorizontal();
        GUILayout.Space(10);    
    }
}
more ▼

answered Feb 26, 2010 at 09:34 AM

eurosat7 gravatar image

eurosat7
277 17 15 25

what if you have "question with answers" being displayed in game. and what would you attach it to. ?? \

Nov 19, 2012 at 08:41 PM aiibee
(comments are locked)
10|3000 characters needed characters left

var newSkin : GUISkin; var logoTexture : Texture2D;

function theFirstMenu() { //layout start GUI.BeginGroup(Rect(Screen.width / 2 - 150, 50, 300, 200));

 //the menu background box
 GUI.Box(Rect(0, 0, 300, 200), "");

 //logo picture
 GUI.Label(Rect(15, 10, 300, 68), logoTexture);

 ///////main menu buttons
 //game start button
 if(GUI.Button(Rect(55, 100, 180, 40), "Start game")) {
 var script = GetComponent("MainMenuScript"); 
 script.enabled = false;
 var script2 = GetComponent("MapMenuScript"); 
 script2.enabled = true;
 }
 //quit button
 if(GUI.Button(Rect(55, 150, 180, 40), "Quit")) {
 Application.Quit();
 }

 //layout end
 GUI.EndGroup(); 

}

function OnGUI () { //load GUI skin GUI.skin = newSkin;

 //execute theFirstMenu function
 theFirstMenu();

}


How do I link this to my first level so that when I click begin game it brings me to the first level. If I need my Map Menu script to do it...here it is.

var newSkin : GUISkin; var mapTexture : Texture2D;

function theMapMenu() { //layout start GUI.BeginGroup(Rect(Screen.width / 2 - 200, 50, 400, 300));

 //boxes
 GUI.Box(Rect(0, 0, 400, 300), "");
 GUI.Box(Rect(96, 20, 200, 200), "");
 GUI.Box(Rect(96, 222, 200, 20), "Coastside Level");

 //map preview/icon
 GUI.Label(Rect(100, 20, 198, 198), mapTexture);

 //buttons
 if(GUI.Button(Rect(15, 250, 180, 40), "start level")) {
 Application.LoadLevel(1);
 }
 if(GUI.Button(Rect(205, 250, 180, 40), "go back")) {
 var script = GetComponent("MainMenuScript"); 
 script.enabled = true;
 var script2 = GetComponent("MapMenuScript"); 
 script2.enabled = false;
 }

 //layout end
 GUI.EndGroup(); 

}

function OnGUI () { //load GUI skin GUI.skin = newSkin;

 //execute theMapMenu function
 theMapMenu();

}

more ▼

answered Feb 16 at 05:00 AM

ViralGameOver gravatar image

ViralGameOver
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5633

asked: Feb 26, 2010 at 05:21 AM

Seen: 59902 times

Last Updated: Feb 16 at 05:00 AM