I’m trying to create menus in my game where I can choose options by the arrows keys on the keyboard so I don’t want the mouse cursor to appear at all. I don’t want to hide it only, I want to disable mouse clicks for the entire game too.
Currently, I have created a Pause Menu with multiple options that I can choose from using the keyboard arrow keys, However, when I click using the mouse anywhere on the screen the buttons on the menu lose focus and I can’t choose from the menu anymore. How can I fix this?
Here is my code for the PauseMenu:
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Pause();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
private void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
the cursor sometimes still appear and even when it is hidden I can still click on the screen and once I click on the screen the menu options get unselected and I can’t choose an option anymore. How can I fix this??