Cursor Lock Mode Documentation / Example
So very very recently unity update to the docs they added some doc about Cursor Lock Mode seen here https://docs.unity3d.com/ScriptReference/CursorLockMode.html However they do not include any examples on how to use it. This is super frustrating because it seems like Screen.lockCursor is disabled / depreciated.
Given that info does anyone have an example of how to hide / completely lock the cursor in the play window? I am trying to setup an FPS and it is VERY VERY hard to test on my multiple monitor setup since the cursor refuses to lock to the play area.
Answer by PizzaPie · Apr 30, 2017 at 11:53 AM
To hide the cursor use :
Cursor.visible = false;
and to reveal it change the value to true. To lock use :
Cursor.lockState = CursorLockMode.Locked;
and to unlock it:
Cursor.lockState = CursorLockMode.None;
So use something like this :
void LockCursor(bool value)
{
Cursor.visible = !value;
if (value)
Cursor.lockState = CursorLockMode.Locked;
else
Cursor.lockState = CursorLockMode.None;
}
if value = true : hides and locks the cursor , if value = false : reveals and unlocks the cursor. And lastly there is the CursorLockMode.Confined to prevent the cursor to go out of the current window. Cheers.
Your answer

Follow this Question
Related Questions
Can't see my custom cursor. 0 Answers
Cursor.SetCursor() not working 1 Answer
UnLock and Show Cursor 1 Answer
How can I make my cursor to follow more faster? (there's too much delay) 0 Answers
Why my Scale Script don't work ? 1 Answer