using UnityEngine;
using System.Collections;
public class QuitGame : MonoBehaviour {
bool showMenu = false;
GUIStyle gustyle;
// Use this for initialization
void Start () {
gustyle = new GUIStyle();
gustyle.fontSize = 20;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape)) {
showMenu = !showMenu; // toggle between true/false
}
}
void OnGUI () {
if (showMenu == false)
{
return;
}
var w = 150;
var h = 150;
Rect rect = new Rect((Screen.width-w)/2, (Screen.height-h)/2, w, h);
// Make a background box
GUI.Box (rect, "Main Menu", gustyle);
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (rect.x + 20, rect.y + 40, 80, 20), "PLAY")) {
//Application.LoadLevel(1);
}
// Make the second button.
if (GUI.Button (new Rect (rect.x + 20, rect.y + 70, 80, 20), "EXIT")) {
Application.Quit ();
}
}
}
Once i added the gustyle to the line:
GUI.Box (rect, "Main Menu", gustyle);
The box is gone. The text is bigger but without the box.
What i want to do is a box in the middle of the screen with some title text size of the box and with some menu buttons inside the box under the title like Play, Stop, Pause, Resume, Quit, Options…etc.
But i can’t make a good box size with the buttons size and texts size.
And another sub question: What is better to use for main menu ? GUI.Box,labels,buttons…or the 3D Text ? Or maybe using the Canvas system ?
This is a screenshot of the main menu without the gustyle:
And this is with the guistyle: