- Home /
Cursor Lock
Hello, i have a browser game with fps so i need to lock the cursor totaly in the game no matter where the player moves the mouse or clicks, how can i do that?
Answer by Ejlersen · Aug 06, 2013 at 06:55 PM
This will lock the cursor to the webplayer:
Screen.lockCursor = true;
In the web player, the cursor may only be locked after the user has clicked on the content and the user has not left the content view with the cursor. After the user presses escape or switches to another application the cursor will be automatically unlocked. The cursor lock will also be lost when exiting full screen mode.
To add the cursor in the webplayer in lock view. I think you could add your own:
Cursor.SetCursor(...);
Yeah i used that but as i said i want the user to be able to move the cursor and click anywhere, so its useless, is there any other way?
ok, but i want the default cursor icon. Should i put null? Also where do i put this command, on update?
I think you can use the hardware cursor. You can probably find it in the documentation. Where to put it? Well, that depends. You could have it on Awake for when you start the game, then have a button or hot key to do the same thing.
Answer by SuperUltraHyper · Feb 17, 2016 at 03:24 PM
All of the cursor stuff must happen in the "OnGUI" method of your script. Ex:
void OnGUI()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}