Simple GUI script in Unity

using UnityEngine;
using System.Collections;
public class GuiScript : MonoBehaviour {
bool showMain = true;
bool showAbout = false;
bool showStart = false;
public Font font;
public Font labelFont;
private GUIStyle testStyle;
int lastLevel = 1;
void OnGUI () {
lastLevel = PlayerPrefs.GetInt(“SavedLevel”);
GUI.skin.font = font;
GUI.skin.label.font = labelFont;
int withFactor = Screen.width / 20;
int heightFactor = Screen.height / 20;
GUI.BeginGroup (new Rect (Screen.width / 2 – 6 * withFactor, Screen.height / 2 – 6 * heightFactor, 12 * withFactor, 12 * heightFactor));
GUI.Box (new Rect (0, 0, 12 * withFactor, 12 * heightFactor), “Arcadian”);
if (showMain) {
if (GUI.Button (new Rect (2 * withFactor, 3 * heightFactor, 8 * withFactor, 2 * heightFactor), “Start the game”)) {
//print (“You clicked the ‘Start the game’ button!”);
showMain = false;
showStart = true;
}
if (GUI.Button (new Rect (2 * withFactor, 6 * heightFactor, 8 * withFactor, 2 * heightFactor), “About”)) {
//print (“You clicked the ‘About’ button!”);
showMain = false;
showAbout = true;
}
if (GUI.Button (new Rect (2 * withFactor, 9 * heightFactor, 8 * withFactor, 2 * heightFactor), “Quit”)) {
//print (“You clicked the ‘Quit’ button!”);
Application.Quit ();
}
}
if (showAbout) {
if (GUI.Button (new Rect (2 * withFactor, 95 * heightFactor/10, 8 * withFactor, 2 * heightFactor), “Back to main menu”)) {
// print (“You clicked the ‘BackToMain’ button!”);
showMain = true;
showAbout = false;
}
GUI.Label (new Rect (20 * withFactor/10, 23 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Developed by EmbeddedSoft Canada © 2014”);
GUI.Label (new Rect (30 * withFactor/10, 33 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Website: www.embeddedsoft.ca”);
GUI.Label (new Rect (38 * withFactor/10, 43 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Twitter: embeddedsoft”);
GUI.Label (new Rect (28 * withFactor/10, 53 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Support: support@embeddedsoft.ca”);
GUI.Label (new Rect (30 * withFactor/10, 63 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “”);
GUI.Label (new Rect (35 * withFactor/10, 73 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Developer: Ranko Rodic”);
GUI.Label (new Rect (28 * withFactor/10, 83 * heightFactor/10, 10 * withFactor, 2 * heightFactor), “Textures and design: Marija Solaja”);
}
if (showStart) {
if (GUI.Button (new Rect (2 * withFactor, 95 * heightFactor/10, 8 * withFactor, 2 * heightFactor), “Back to main menu”)) {
print (“You clicked the ‘BackToMain’ button!”);
showMain = true;
showStart = false;
}
if (GUI.Button (new Rect (10 * withFactor/10, 25 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 1”))
{
Application.LoadLevel(1);
}
if (lastLevel<2)
{GUI.enabled=false;}
if (GUI.Button (new Rect (45 * withFactor/10, 25 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 2”))
{
Application.LoadLevel(3);
}
if (lastLevel<3)
{GUI.enabled=false;}
if (GUI.Button (new Rect (80 * withFactor/10, 25 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 3”))
{
Application.LoadLevel(5);
}
if (lastLevel<4)
{GUI.enabled=false;}
if (GUI.Button (new Rect (10 * withFactor/10, 48 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 4”))
{
Application.LoadLevel(7);
}
//GUI.Button (new Rect (10 * withFactor/10, 48 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 4”);
if (lastLevel<5)
{GUI.enabled=false;}
if (GUI.Button (new Rect (45 * withFactor/10, 48 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 5”))
{
Application.LoadLevel(9);
}
if (lastLevel<6)
{GUI.enabled=false;}
if (GUI.Button (new Rect (80 * withFactor/10, 48 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 6”))
{
Application.LoadLevel(11);
}
if (lastLevel<7)
{GUI.enabled=false;}
if (GUI.Button (new Rect (10 * withFactor/10, 72 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 7”))
{
Application.LoadLevel(13);
}
if (lastLevel<8)
{GUI.enabled=false;}
if (GUI.Button (new Rect (45 * withFactor/10, 72 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 8”))
{
Application.LoadLevel(15);
}
if (lastLevel<9)
{GUI.enabled=false;}
if (GUI.Button (new Rect (80 * withFactor/10, 72 * heightFactor/10, 3 * withFactor, 2 * heightFactor), “Level 9”))
{
Application.LoadLevel(17);
}
}
GUI.skin.button.fontSize = 3 * withFactor / 5;
GUI.skin.box.fontSize = 4 * withFactor / 5;
GUI.skin.label.fontSize = 2 * withFactor / 5;
GUI.EndGroup ();
}
}
Add your comment

Your email address will not be published. Required fields are marked *