When the ‘ESC’ is press, Unity automatically Unlock the cursor. Is a way to change if cursor is lock or unlock only in script? Simple Question.
Some of you help me but i found a fact which is useful to know about pressing the Escape Key, Unity UnLock the cursor after pressing the Escape Key. What it mean: GetKeyDown cant’t lock the cursor because Unity will unlock it after. I tried to Update for checking if the cursor is unlock and no GUI or UI are open. Sorry for bad english…
From the scripting reference
In the Web Player and Editor the
cursor will automatically be reset
when you press escape. In the
Standalone Player you have full
control over the mouse cursor, thus it
won’t automatically be reset unless
you switch applications.
So if making a standalone build, it isn’t something to be concerned about, and in a web player build it’s probably a good thing that the user can free the mouse by pressing esc.
Just for general interest I tested if it’s possible to override Unity’s behaviour by say, locking the mouse on the next frame but it seemed to me that at least in Unity Editor the mouse could not be locked again before the user had clicked inside the game window again.