Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PopupMenu : MonoBehaviour {
- bool ShowMenu = false;
- Rect window;
- void Start () {
- Screen.lockCursor = true;
- // hide cursor
- Screen.showCursor = false;
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown(KeyCode.Escape)) {
- ShowMenu = !ShowMenu;
- try {
- if (ShowMenu) {
- GameObject.Find("Player").GetComponent<Movement>().Pause();
- Screen.lockCursor = false;
- // toggle cursor
- Screen.showCursor = true;
- } else {
- GameObject.Find("Player").GetComponent<Movement>().UnPause();
- Screen.lockCursor = true;
- // toggle cursor
- Screen.showCursor = false;
- }
- } catch {}
- }
- window = new Rect(Screen.width/2-50,Screen.height/2-50,100,100);
- }
- void OnGUI() {
- if (ShowMenu) {
- window = new Rect(Screen.width/2-50,Screen.height/2-50,100,100);
- GUI.Box(window, new Texture());
- if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 10f, 75, 20), "Return")) {
- try {
- Screen.lockCursor = false;
- Screen.showCursor = true;
- ShowMenu = false;
- GameObject.Find("Player").GetComponent<Movement>().UnPause();
- } catch {}
- }
- if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 40f, 75, 20), "Settings")) {
- }
- if (GUI.Button(new Rect(window.xMin + (window.width/2-37.5f), window.yMin + 70f, 75, 20), "End Game")) {
- Screen.lockCursor = false;
- Screen.showCursor = true;
- Application.LoadLevel("MainMenu");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment