- Home /
Check if mouse cursor is locked
I'm making a game and I want to release the mouse when the player presses Escape or P. How would I check if the mouse is locked or not?
That depends on how you lock it in the first place. Unity has Screen.lockCursor, if that's what you're using, just check if it's true.
Answer by Forsyth · Jul 27, 2013 at 03:46 AM
You can use:
if(Screen.lockCursor == true)
to check if the cursor is currently locked.
But presumably you have gameplay where you want the mouse to be locked and then you want the mouse to be unlocked when you press escape or p so you can use a menu or something.
Use:
if(Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape))
Screen.lockCursor = false;
when you want to unlock the mouse cursor. In the same function, you can also activate the menu or whatever you need the mouse cursor for.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Clamp a mouse around several 2d objects 1 Answer
C# Emit Particle Upon Left Mouse Click 2 Answers
Trying to make a Point system that references a Prefab. 1 Answer