Mouse cursor visibility issue.
I have turned off the mouse cursor in the game. I want it to appear when the Pause Menu is activated, and disappear when it's closed. I have the following code to do this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
} else
{
Pause();
}
}
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
Cursor.visible = true;
GameIsPaused = true;
}
// Buttons:
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
Cursor.visible = false;
GameIsPaused = false;
}
public void OptionsMenu()
{
Debug.Log("Options menu displays.");
}
public void QuitGame()
{
Debug.Log("Quitting game.");
Application.Quit();
}
}
The cursor appears always as expected. If you click the Resume UI button, which calls the Resume() method, then the mouse cursor disappears as expected. However, if you exit the Pause Menu by hitting the Escape key, which also calls the Resume() method, the mouse cursor doesn't disappear.
Any ideas why??? Thank you for your help.
Comment
Your answer
Follow this Question
Related Questions
Cursor.visible doesn't seem to work in Standalone 0 Answers
Cursor does not contain a definition for 'lockState'/'visible' 2 Answers
UI text wont highlight 0 Answers
Mouse Look Script Not Working 1 Answer