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().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().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().Play();
Time.timeScale = 1; // 继续
PauseMenu.SetActive(false);
}
......
↧