I want to lock mouse cursor after returning from other application by using alt+tab. Everything work fine when I lock it at OnApplicationFocus. But when I lock it at OnApplicationPause, it doesn’t work.
Code:
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
Debug.Log("Pause status: " + pauseStatus + " | Lock state: " + Cursor.lockState + " | Visible: " + Cursor.visible);
}
Result:
Below is result at start of the game. Everything is corrected.
Below is result when switch to other application by using alt+tab. Everything is corrected.
Below is result when return from other application by using alt+tab. Visible is corrected. But lock state should be Locked.
I am using unity 2017.3.