UnLock and Show Cursor
I am trying to make it so that on the start of my game, the cursor will show and it will unlock it. I have made an empty game object and put this script on it.
void Start () {
Screen.lockCursor = false;
Cursor.visible = true;
}
When I am in the editor, there is nothing to lock the cursor so I don't know if it is working, but when I build the game, the cursor does not show.
How can I make my finished game show the cursor and let me use it?
I am using C#.
Does it matter that I have a custom cursor? Could the cursor icon just be not showing when I build the game? It works in the editor.
I have found that the cursor does show when I remove a custom cursor. Why does it not work with a custom cursor?
Answer by aule · May 24, 2016 at 01:47 AM
You can use Cursor.lockState
to lock the cursor.
Just implement this in your script
void SetCursorState (CursorLockMode wantedMode)
{
Cursor.lockState = wantedMode;
// Hide cursor when locking
Cursor.visible = (CursorLockMode.Locked != wantedMode);
}
Is SetCursorState a built in function, or is that just the name of the function you made? Also, I used Cursor.visible, but the cursor still did not show when I built the game. Does the Cursor.Visible not use a bool true or false?
I just want the cursor to be unlocked my entire game, but my cursor doesn't show when I build it.