Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PauseMenuScript : MonoBehaviour
- {
- public GUISkin myskin; //custom GUIskin reference
- public string levelToLoad;
- public bool paused = false;
- public string current;
- private void Start()
- {
- Time.timeScale=1; //Set the timeScale back to 1 for Restart option to work
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape) ) //check if Escape key/Back key is pressed
- {
- if (!paused)
- {
- paused = true; //pause the game if not paused
- current = "MAIN"; //everytime I press ESC
- }
- else
- paused = false; //unpause the game if already paused
- }
- if(paused)
- Time.timeScale = 0; //set the timeScale to 0 so that all the procedings are halted
- else
- Time.timeScale = 1; //set it back to 1 on unpausing the game
- }
- private void OnGUI()
- {
- GUI.skin=myskin; //use the custom GUISkin
- if (paused)
- {
- if(current == "MAIN")
- {
- GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "PAUSED");
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESUME"))
- {
- paused = false;
- }
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+2*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESTART"))
- {
- Application.LoadLevel("map_forest");
- }
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+3*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "SETTINGS"))
- {
- current = "SETTINGS";
- }
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+4*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "MAIN MENU"))
- {
- Application.LoadLevel("main-menu");
- }
- }
- if (current == "SETTINGS")
- {
- GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "SETTINGS");
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+2*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "INSTRUCTIONS"))
- {
- current = "INSTRUCTIONS";
- }
- if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+3*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESOLUTION"))
- {
- current = "RESOLUTION";
- }
- }
- if(current == "INSTRUCTIONS")
- {
- GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "INSTRUCTIONS");
- if(GUI.Button (new Rect(Screen.width/4+10, Screen.height/6*5, Screen.width/2-20, Screen.height/10),"RETURN TO SETTINGS"))
- {
- current = "SETTINGS";
- }
- GUI.Box (new Rect(Screen.width/4+10, Screen.height/4+30, Screen.width/2-20, Screen.height/3),"QSDZ to move, F to Fire, Left Click for Melee, Space to Jump");
- }
- if(current == "RESOLUTION")
- {
- GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "RESOLUTION");
- if(GUI.Button (new Rect(Screen.width/4+10, Screen.height/6*5, Screen.width/2-20, Screen.height/10),"RETURN TO SETTINGS"))
- {
- current = "SETTINGS";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement