using UnityEngine; using UnityEngine.UI; public class Main : Button { void OnGUI() { // Q: Enter PointerLock state if (Input.GetKeyDown(KeyCode.Q)) { EnterPointerLock(); } // O: Exit PointerLock state // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor. // When entered with Q: Works as intended. Released Pointer Lock and Reveals the Cursor. if (Input.GetKeyDown(KeyCode.O)) { ExitPointerLock(); } // ESC: Exit PointerLock state // When entered with CLICK: Releases Pointer Lock but does not Reveal Cursor. // When entered with Q: On FIRST press it Releases Pointer Lock (cursor still hidden), on SECOND press it Reveals the Cursor! if (Input.GetKeyDown(KeyCode.Escape)) { ExitPointerLock(); } } void EnterPointerLock() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } void ExitPointerLock() { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } public override void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData) { EnterPointerLock(); } }