Hello, I am using this script to control locking of the mouse in Unity WebPlayer, but there are some weird irregularities.
// for Standalone initial screen locking
function Start ()
{
Screen.lockCursor = true; // Start the game with the cursor locked or not
}
function Update () {
if(Screen.lockCursor == false && Input.GetKeyUp("p"))
{
Screen.lockCursor = true;
}
else if (Input.GetKeyUp("p"))
{
Screen.lockCursor = false;
}
}
// Control Screen locking when focusing on the webplayer
function OnApplicationFocus (){
if(Screen.lockCursor == false){
Screen.lockCursor = true;
}
}
When I load the webplayer the mouse is free to move the camera and I must click outside the player and then back to the player to get the mouse lock to activate (using Firefox). However the worst glitch is that I have a bunch of objects in the scene that I am using as triggers (for things like picking up items, turning on lights, starting animations etc) , and when the mouse is not visible from locking the cursor I cannot click any of them. When I start the game if I don’t click outside and back in to activate the focus part of the script I can click anything just fine (but the mouse is moving about the scene without being in the middle of course). Every time I toggle the script when locked and centered it I cannot click anywhere though looking around is normal, and as soon as I toggle it off I can click everything again. To make it even more confusing, using the exact same build in the standalone player and in the editor nothing is wrong at all. I would really appreciate help with this as I’ve spent an entire day trying different configurations to fix this.