Hey guys, I am doing a little project and was just wondering if/how I can pause a game behind a pause screen.
This is my interaction menu so far;
using UnityEngine;
using System.Collections;
public class InteractionMenu : MonoBehaviour {
private bool pressed;
private bool EscapeMenu;
private bool Inventory;
private bool Chat;
public GameObject EscapeMenuObj;
//public GameObject InventoryObj;
//public GameObject ChatObj;
void Start () {
pressed = false;
EscapeMenu = false;
Inventory = false;
Chat = false;
}
void Update () {
//Escape Menu
if (Input.GetKey (KeyCode.Escape)) {
if (!pressed) {
pressed = true;
if (!EscapeMenu) {
CursorLock ("Off");
EscapeMenu = true;
EscapeMenuObj.SetActive (true);
} else {
CursorLock ("On");
EscapeMenu = false;
EscapeMenuObj.SetActive (false);
}
}
} else {
pressed = false;
}
//Inventory
if (Input.GetKey (KeyCode.E)) {
if (!Inventory) {
CursorLock ("Off");
Inventory = true;
//InventoryObj.enabled = true;
} else {
CursorLock ("On");
Inventory = false;
//InventoryObj.enabled = false;
}
}
//Chat
if (Input.GetKey (KeyCode.T)) {
if (!Chat) {
CursorLock ("Off");
Chat = true;
//ChatObj.enabled = true;
} else {
CursorLock ("On");
Chat = false;
//ChatObj.enabled = false;
}
}
}
void CursorLock(string Switch){
if (Switch == "On") {
Cursor.visible = false;
Screen.lockCursor = true;
} else {
Cursor.visible = true;
Screen.lockCursor = false;
}
}
}