- Home /
screen.lockcursor locks the cursor in wrong place
void Start () {
Screen.lockCursor = false;
Screen.lockCursor = true;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Tab))
{
Screen.lockCursor = !Screen.lockCursor;
}
}
Such a simple code and it doesn't work. I attached it to an empty GO inside the scene. The problem seems to be that the cursor locks in wrong place (an afaik it should lock in the middle of the screen) - when I hit tab for the first time I can see it's location and it's usually somewhere far right - after that when I hit tab, everything is back to normal, so the problem seems to appear only on level startup. Any thoughts?
Got a similar problem. When starting the game and pressing any button the mouse jumps out of its "lock" and lands in the inspector and I have to position the mouse manually in the game view for it to work again.
is there a command to center the cursor other than this? hiding part works fine
Answer by Bunny83 · Aug 07, 2011 at 12:19 AM
That's just an issue in the editor. It have been discovered long time ago ;)
Any build version should be ok.
In the editor a lot things happens additionally. When switching from edit to run mode the whole scene gets serialized and recreated. Also the behaviour is different when you have both view visible (scene view and game view) instead having them in the same dock window as tabs.
Personally i always have both visible (game view at the top scene view below)
Your answer
Follow this Question
Related Questions
Lock cursor everywhere not center,how? 1 Answer
One Last GUI Question 1 Answer
Locking cursor Issue - Flash 1 Answer
Cant unlock cursor with FPS prefab 2 Answers
Unity 3D Screen.lockCursor Problems 2 Answers