Some problem with cursor

Hello friends.
In my project i need a lock cursor (centre).
I used that code in Update of standart FPS controller script (i deleted the same code in MouseLook):

Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Screen.lockCursor = true;

But when i switch application (alt+tab for example) and then switch to my game, cursor not at centre. But still not visible. How can i fix it? Tnx.

Cursor.lockState = CursorLockMode.Locked and Screen.lockCursor = true do not worked correctly.

U need add this script to the camera :slight_smile:

public class AppPause : MonoBehaviour
{
void OnApplicationFocus(bool hasFocus)
{
ControlCursor( !hasFocus );
}

void OnApplicationPause(bool pauseStatus)
{
    ControlCursor( pauseStatus );
}

void ControlCursor(bool isPaused)
{
    if (isPaused)
    {
        Debug.Log("PAUSED");
        Cursor.visible = true;
        Cursor.lockState = CursorLockMode.None;
    }
    else
    {
        Debug.Log("play mode");
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
    }
}

}