- Home /
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?
Answer by jitesh · Feb 26, 2010 at 06:04 AM
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
Answer by eurosat7 · Feb 26, 2010 at 09:34 AM
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);
}
}
what if you have "question with answers" being displayed in game. and what would you attach it to. ?? \
Answer by Will · Feb 26, 2010 at 06:04 AM
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.
Answer by ViralGameOver · Feb 16, 2014 at 05:00 AM
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();
}