Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PauseMenuScript : MonoBehaviour
  5. {
  6.     public GUISkin myskin;  //custom GUIskin reference
  7.     public string levelToLoad;
  8.     public bool paused = false;
  9.     public string current;
  10.    
  11.     private void Start()
  12.     {
  13.         Time.timeScale=1; //Set the timeScale back to 1 for Restart option to work  
  14.     }
  15.    
  16.     private void Update()
  17.     {
  18.        
  19.         if (Input.GetKeyDown(KeyCode.Escape) ) //check if Escape key/Back key is pressed
  20.         {
  21.             if (!paused)
  22.             {
  23.                 paused = true;  //pause the game if not paused
  24.                 current = "MAIN"; //everytime I press ESC
  25.             }
  26.             else
  27.                 paused = false; //unpause the game if already paused
  28.         }
  29.        
  30.         if(paused)
  31.             Time.timeScale = 0;  //set the timeScale to 0 so that all the procedings are halted
  32.         else
  33.             Time.timeScale = 1;  //set it back to 1 on unpausing the game
  34.        
  35.     }
  36.    
  37.     private void OnGUI()
  38.     {
  39.         GUI.skin=myskin;   //use the custom GUISkin
  40.        
  41.         if (paused)
  42.         {    
  43.  
  44.             if(current == "MAIN")
  45.             {
  46.                 GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "PAUSED");
  47.                
  48.                 if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESUME"))
  49.                 {
  50.                     paused = false;
  51.                 }
  52.                
  53.                 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"))
  54.                 {
  55.                     Application.LoadLevel("map_forest");
  56.                 }
  57.                 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"))
  58.                 {
  59.                     current = "SETTINGS";
  60.                 }
  61.                 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"))
  62.                 {
  63.                     Application.LoadLevel("main-menu");
  64.                 }
  65.             }
  66.             if (current == "SETTINGS")
  67.             {
  68.                 GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "SETTINGS");
  69.                 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"))
  70.                 {
  71.                     current = "INSTRUCTIONS";
  72.                 }
  73.                 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"))
  74.                 {
  75.                     current = "RESOLUTION";
  76.                 }
  77.             }
  78.             if(current == "INSTRUCTIONS")
  79.             {
  80.                 GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "INSTRUCTIONS");
  81.                 if(GUI.Button (new Rect(Screen.width/4+10, Screen.height/6*5, Screen.width/2-20, Screen.height/10),"RETURN TO SETTINGS"))
  82.                 {
  83.                     current = "SETTINGS";
  84.                 }
  85.                 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");
  86.             }
  87.             if(current == "RESOLUTION")
  88.             {
  89.                 GUI.Box(new Rect(Screen.width/4, Screen.height/5, Screen.width/2, 80), "RESOLUTION");
  90.                 if(GUI.Button (new Rect(Screen.width/4+10, Screen.height/6*5, Screen.width/2-20, Screen.height/10),"RETURN TO SETTINGS"))
  91.                 {
  92.                     current = "SETTINGS";
  93.                 }
  94.             }
  95.  
  96.  
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement