- Home /
Screen.LockCursor working in editor but not in webplayer
As stated in the title, when I play my game in the editor it works perfectly. When I build it out into a webplayer and play it the cursor is still visible and can leave the window even though I have clicked into the content. Please help me as this is getting very frusterating...I have in the Awake() of my Camera to Screen.lockCursor = true;
I thought it may be because I had run in background on, however this didnt solve the issue.
Thank you for your time and I look forward to hearing from someone soon!
Answer by gruhm · Oct 24, 2011 at 06:14 PM
From the Documentation:
In the web player the cursor may only 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. You can query if the cursor is currently locked by checking the lockCursor state. To provide a good user experience it is recommended to only lock the cursor as a result of pressing a button. Also you should check if the cursor got unlocked, in order to e.g. pause the game or bring up a game menu. In the Web Player and Editor the cursor will automatically be unlocked when you press escape. In the Standalone Player you have full control over mouse locking thus it won't automatically lose mouse lock unless you switch applications.
I have read the documentation on this, and as stated in the question clicking in the content does not initially lock the cursor like it was supposed to the mouse just simply stays visible like nothing happened...I have played a few demos of other games that do the same thing and it works just fine...
Answer by Bezzy · Jan 09, 2012 at 04:36 PM
I've had this problem, and got around it with... not the most elegant thing, but it works. In your update, do this:
if(Screen.lockCursor == false)
{
if(Input.GetMouseButtonDown(0))
{
Screen.lockCursor = true;
}
}
The reason it won't get called from "Start" is because you could potentially steal focus without the user allowing you to.
Your answer
Follow this Question
Related Questions
Build unity application using a unity application. 1 Answer
Problem Loading Asset Bundles on Web Player 1 Answer
How to stop mouse getting out of the game, my game is in webplayer? 2 Answers
Folder for non-editor dll 0 Answers
[SOLVED] Unity 5: Lightmap dissapearing in web player but not in editor 1 Answer