- Home /
Question by
55555Ice55555 · Jul 03, 2015 at 01:00 PM ·
unity 5cursorlock-cursor
Mouse cursor doesn't lock Unity 5
Recently I have ran into a problem where I need to lock my mouse cursor but it doesn't lock. I have tried almost everything but the cursor just doesn't want to lock. Any ideas on how to lock it ?
My version of Unity is 5.1.1f1
Here is my code:
public bool locked = false;
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
locked = !locked;
}
if (locked)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
Comment
Do you see this behavior just in the editor, or does it also not lock in a standalone build?
Your answer
Follow this Question
Related Questions
How to move my cursor to a specific position and then lock it to that position. 0 Answers
Can I lock a cursor without hiding it? 0 Answers
Unable Escape Key to Unlock cursor 2 Answers
Cursor Problem / Toggle Lock and Unlock 0 Answers
Hiding a Cursor? 3 Answers