- Home /
How to make in main menu?
how to make a button that open selection of themes once you select the theme theme is in main menu scene
sorry for bad English
Answer by Streamline Games · Nov 04, 2012 at 04:11 PM
If you mean you select a them by name and it'll load that them then you:
you have a drop down menu of theme names. Once you select the theme it'll load the theme. Think of it like this a theme is a GUI, you can make custom GUI and use them by coding. Basically you making it so that when you click the text it'll display the GUI attached to that piece of code. I would give you some code, but you need to learn by your self. Sorry.
Answer by domtate123 · Nov 04, 2012 at 04:10 PM
This is script i use for my main menu page... not 100% if this is what you asking for...
using UnityEngine; using System.Collections;
public class Menu : MonoBehaviour { public GUISkin guiSkin; public Texture2D background, LOGO; public bool DragWindow = false; public string levelToLoadWhenClickedPlay = ""; public string[] AboutTextLines = new string[0];
private string clicked = "", MessageDisplayOnAbout = "About \n ";
private Rect WindowRect = new Rect((Screen.width / 2) - 100, Screen.height / 2, 200, 150);
private float volume = 1.0f;
private void Start()
{
for (int x = 0; x < AboutTextLines.Length;x++ )
{
MessageDisplayOnAbout += AboutTextLines[x] + " \n ";
}
MessageDisplayOnAbout += "Press Esc To Go Back";
}
private void OnGUI()
{
if (background != null)
GUI.DrawTexture(new Rect(0,0,Screen.width , Screen.height),background);
if (LOGO != null && clicked != "about")
GUI.DrawTexture(new Rect((Screen.width / 2) - 440, 150, 900, 350), LOGO);
GUI.skin = guiSkin;
if (clicked == "")
{
WindowRect = GUI.Window(0, WindowRect, menuFunc, "Main Menu");
}
else if (clicked == "options")
{
WindowRect = GUI.Window(1, WindowRect, optionsFunc, "Options");
}
else if (clicked == "about")
{
GUI.Box(new Rect (0,0,Screen.width,Screen.height), MessageDisplayOnAbout);
}else if (clicked == "resolution")
{
GUILayout.BeginVertical();
for (int x = 0; x < Screen.resolutions.Length;x++ )
{
if (GUILayout.Button(Screen.resolutions[x].width + "X" + Screen.resolutions[x].height))
{
Screen.SetResolution(Screen.resolutions[x].width,Screen.resolutions[x].height,true);
}
}
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Back"))
{
clicked = "options";
}
GUILayout.EndHorizontal();
}
}
private void optionsFunc(int id)
{
if (GUILayout.Button("Resolution"))
{
clicked = "resolution";
}
GUILayout.Box("Volume");
volume = GUILayout.HorizontalSlider(volume ,0.0f,1.0f);
AudioListener.volume = volume;
if (GUILayout.Button("Back"))
{
clicked = "";
}
if (DragWindow)
GUI.DragWindow(new Rect (0,0,Screen.width,Screen.height));
}
private void menuFunc(int id)
{
//buttons
if (GUILayout.Button("Play Game"))
{
//play game is clicked
Application.LoadLevel(levelToLoadWhenClickedPlay);
}
if (GUILayout.Button("Options"))
{
clicked = "options";
}
if (GUILayout.Button("About"))
{
clicked = "about";
}
if (GUILayout.Button("Quit Game"))
{
Application.Quit();
}
if (DragWindow)
GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
}
private void Update()
{
if (clicked == "about" && Input.GetKey (KeyCode.Escape))
clicked = "";
}
}
`Blockquote`
Answer by Anxo · Nov 03, 2012 at 11:45 PM
You can make your life easy if you download the NGUI package from the Unity Assests store. It is fast and easy to make menues and things of that nature.
Answer by Coreyf716 · Nov 04, 2012 at 12:15 AM
Maybe GUI?
var isMenu : boolean;
function OnGUI () {
if (GUI.Button (Rect (0, 0, 100, 100), "Menu")) {
isMenu = !isMenu;
}
if (isMenu) {
if (GUI.Button (Rect (150, 150, 100, 100), "Quit")) {
Application.LoadLevel("//");
}
}
}
I think this is what you are talking about. If it isn't, let me know.
Hope this helps.
Answer by domtate123 · Nov 04, 2012 at 04:10 PM
This is script i use for my main menu page... not 100% if this is what you asking for...
using UnityEngine; using System.Collections;
public class Menu : MonoBehaviour { public GUISkin guiSkin; public Texture2D background, LOGO; public bool DragWindow = false; public string levelToLoadWhenClickedPlay = ""; public string[] AboutTextLines = new string[0];
private string clicked = "", MessageDisplayOnAbout = "About \n ";
private Rect WindowRect = new Rect((Screen.width / 2) - 100, Screen.height / 2, 200, 150);
private float volume = 1.0f;
private void Start()
{
for (int x = 0; x < AboutTextLines.Length;x++ )
{
MessageDisplayOnAbout += AboutTextLines[x] + " \n ";
}
MessageDisplayOnAbout += "Press Esc To Go Back";
}
private void OnGUI()
{
if (background != null)
GUI.DrawTexture(new Rect(0,0,Screen.width , Screen.height),background);
if (LOGO != null && clicked != "about")
GUI.DrawTexture(new Rect((Screen.width / 2) - 440, 150, 900, 350), LOGO);
GUI.skin = guiSkin;
if (clicked == "")
{
WindowRect = GUI.Window(0, WindowRect, menuFunc, "Main Menu");
}
else if (clicked == "options")
{
WindowRect = GUI.Window(1, WindowRect, optionsFunc, "Options");
}
else if (clicked == "about")
{
GUI.Box(new Rect (0,0,Screen.width,Screen.height), MessageDisplayOnAbout);
}else if (clicked == "resolution")
{
GUILayout.BeginVertical();
for (int x = 0; x < Screen.resolutions.Length;x++ )
{
if (GUILayout.Button(Screen.resolutions[x].width + "X" + Screen.resolutions[x].height))
{
Screen.SetResolution(Screen.resolutions[x].width,Screen.resolutions[x].height,true);
}
}
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Back"))
{
clicked = "options";
}
GUILayout.EndHorizontal();
}
}
private void optionsFunc(int id)
{
if (GUILayout.Button("Resolution"))
{
clicked = "resolution";
}
GUILayout.Box("Volume");
volume = GUILayout.HorizontalSlider(volume ,0.0f,1.0f);
AudioListener.volume = volume;
if (GUILayout.Button("Back"))
{
clicked = "";
}
if (DragWindow)
GUI.DragWindow(new Rect (0,0,Screen.width,Screen.height));
}
private void menuFunc(int id)
{
//buttons
if (GUILayout.Button("Play Game"))
{
//play game is clicked
Application.LoadLevel(levelToLoadWhenClickedPlay);
}
if (GUILayout.Button("Options"))
{
clicked = "options";
}
if (GUILayout.Button("About"))
{
clicked = "about";
}
if (GUILayout.Button("Quit Game"))
{
Application.Quit();
}
if (DragWindow)
GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
}
private void Update()
{
if (clicked == "about" && Input.GetKey (KeyCode.Escape))
clicked = "";
}
}