How can i lock the mouse cursor in the middle of the screen ?

What i’m doing now is in the Update:

void Update ()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.lockState = CursorLockMode.None;
    }

But that make the cursor shaking/stuttering when moving the mouse around. And in unity 5.6.1f1 Personal the class Screen don’t have the property lockCursor.

Is there any other easy way to center and lock the mouse cursor ?

Get rid of the second line; changing it from locked to not locked every frame is contradictory and won’t work. Also you can just put it in Start; no sense setting every frame. Personal has no differences from any other license as far as engine features…the Screen class has no lockCursor property. (It did a long time ago.)

–Eric

Found a solution. Only Locked will make the cursor invisible.
The solution is to put the part of the mouse cursor only in the Start and like this:

void Start ()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.lockState = CursorLockMode.Confined;
    }

This will lock the mouse cursor in the center of the screen and also will be visible.
I forgot to mention in my question that i want to keep the mouse cursor visible.

I know this is old, but this is what came up when I was googling for something similar. You can’t have 2 lock states. In this case the lockstate is simply Confined. It’s either Locked, Confined, or None. Cursor.visible is where you set the cursor’s visibility.

Yes, but in the unity manual it says that CursorLockMode.Locked makes the cursor invisible, regardless of the value of Cursor.visible=true;
I tried having it locked and visible that way and didn’t work. And then i found that line that I mention above and i got frustrated!!!
The only thing I can think as a solution, is to lock the cursor and put a dot in the middle of the screen, and have it to always be there.

1 Like

What’s the point of locking the cursor but keeping it visible?

2 Likes

In case you are making an fps game and want to see the cursor, for example

1 Like