Komak57

PopupMenu

Jul 10th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PopupMenu : MonoBehaviour {
  5.     bool ShowMenu = false;
  6.     Rect window;
  7.     void Start () {
  8.         Screen.lockCursor = true;
  9.         // hide cursor
  10.         Screen.showCursor = false;
  11.     }
  12.    
  13.     // Update is called once per frame
  14.     void Update () {
  15.         if (Input.GetKeyDown(KeyCode.Escape)) {
  16.             ShowMenu = !ShowMenu;
  17.             try {
  18.                 if (ShowMenu) {
  19.                     GameObject.Find("Player").GetComponent<Movement>().Pause();
  20.                     Screen.lockCursor = false;
  21.                     // toggle cursor
  22.                     Screen.showCursor = true;
  23.                 } else {
  24.                     GameObject.Find("Player").GetComponent<Movement>().UnPause();
  25.                     Screen.lockCursor = true;
  26.                     // toggle cursor
  27.                     Screen.showCursor = false;
  28.                 }
  29.             } catch {}
  30.            
  31.         }
  32.        
  33.         window = new Rect(Screen.width/2-50,Screen.height/2-50,100,100);
  34.     }
  35.     void OnGUI() {
  36.         if (ShowMenu) {
  37.             window = new Rect(Screen.width/2-50,Screen.height/2-50,100,100);
  38.             GUI.Box(window, new Texture());
  39.             if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 10f, 75, 20), "Return")) {
  40.                 try {
  41.                     Screen.lockCursor = false;
  42.                     Screen.showCursor = true;
  43.                     ShowMenu = false;
  44.                     GameObject.Find("Player").GetComponent<Movement>().UnPause();
  45.                 } catch {}
  46.             }
  47.             if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 40f, 75, 20), "Settings")) {
  48.             }
  49.             if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 70f, 75, 20), "End Game")) {
  50.                
  51.                 Screen.lockCursor = false;
  52.                 Screen.showCursor = true;
  53.                 Application.LoadLevel("MainMenu");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment