I have Screen.showCursor set to false after the level is loaded(Not in this script). However I want the cursor to toggle each time input is received from the escape key. I know my Input.getKey stuff is working correctly because the GUI toggle works fine.
In case its not clear what I am trying to do. The user hits escape to bring up a menu–Then the mouse appears–They hit escape again and the cursor disappears! Not sure why my ! toggles aren’t working
using UnityEngine;
using System.Collections;
public class GuiMenu : MonoBehaviour {
public bool menuShow = false;
public int menuX;
public int menuY;
void Update(){
if(Input.GetKeyDown("escape")){
menuShow = !menuShow;
Screen.showCursor = !Screen.showCursor;
Screen.lockCursor = !Screen.lockCursor;
}
}
void OnGUI(){
if(menuShow){
GUI.Box(new Rect(menuX, menuY, 100, 160), "Test Pause");
GUI.BeginGroup(new Rect(menuX, menuY, 100, 160));
if (GUI.Button(new Rect(10, 10, 80, 40), "Resume")){
menuShow = !menuShow;
Screen.showCursor = !Screen.showCursor;
Screen.lockCursor = !Screen.lockCursor;
}
GUI.Button(new Rect(10, 60, 80, 40), "Settings");
if (GUI.Button(new Rect(10, 110, 80, 40), "Quit")){
Application.Quit();
}
GUI.EndGroup();
}
}
}