- Home /
Question by
z741092665 · Jun 10, 2017 at 02:31 PM ·
cursormouselooklockcursor
Cursor.LockState = CursorLockMode.Locked doesn‘t works。
i wanted to create a pause menu screen and make it when it is on the cursor lock mode is in none and when the menu is off the cursor is locked, but when i try to lock exiting from the menu it doasnt locks.
here is my code:
void Update()
{
menuTimer = GetComponent<panel_manager>().timer;
//Debug.Log(menuTimer);
if (Input.GetKeyDown(KeyCode.Escape) && PauseMenu.active == false && menuTimer == 0)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
Time.timeScale = 0; // 暂停
m_player.enabled = false;
waterAudio.SetActive(false);
BGMAudio.GetComponent<AudioSource>().Pause();
PauseMenu.SetActive(true);
}
else if (Input.GetKeyDown(KeyCode.Escape) && PauseMenu.active == true && quitWindow.active == false && menuTimer == 0)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
if (Cursor.lockState == CursorLockMode.Locked)
{
Debug.Log("123");
}
m_player.enabled = true;
waterAudio.SetActive(true);
BGMAudio.GetComponent<AudioSource>().Play();
Time.timeScale = 1; // 继续
PauseMenu.SetActive(false);
}
......
Comment
Are you sure you are hitting the else if logic?
else if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape) && Pause$$anonymous$$enu.active == true && quitWindow.active == false && menuTimer == 0)