- Home /
Cursor not locking, most likely a bug
So I want to make a pause screen where you can control your mouse and once you click escape you get out of the menu where your cursor is locked.
I searched cursor.lockstate and got a script that allows you to toggle the cursor lockstate, which I changed it a bit so instead of using a GUI it uses the escape key.
The script also has a just in case part where it hides the cursor if the cursor is locked (locked automatically hides the cursor).
So I start off by locking my cursor inside void start() which works fine but once I hit escape to use my cursor, the cursor is hidden only when inside the gaming screen and if I move the mouse out of the gaming screen to click pause, the mouse shows. I then hit escape to lock the mouse but nothing seems to change at all.
This is the script I found which i changed to use key inputs and removed the confined mode. https://docs.unity3d.com/ScriptReference/Cursor-lockState.html
Thanks for the help!
Answer by Koyemsi · Apr 05, 2018 at 11:06 AM
Had about the same issue. Once ESC had been pressed (or anything that was defined to unlock cursor), I never get my cursor to stay locked and invisible again outside of the play window. Maybe this is not a bug ; it may have been intentionally designed that way for some reason. However it seems to occur only within Unity, when in play mode ; everything works fine for me in a standalone build .
Well, if it works when built than it’s still bearable. Thanks!
Your answer
Follow this Question
Related Questions
LockCursor script not working as intended 3 Answers
Unity changes mouse speed when it's compiling 0 Answers
Cursor lock not working 0 Answers
Box Collider on Spring Joint Randomly Stops Working in Editor and Builds 1 Answer
MouseLock is not working 2 Answers