- Home /
How to hide cursor and disable mouse click?
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??
You can pretty much override the cursor locked state by clicking around the Unity Editor when game is in play mode. In built game this should not be a problem. So try to build it and check if this still happens.
Answer by lestatos86 · Dec 08, 2021 at 07:37 PM
I do pretty much think that if you pause a game , you should let the user use any input mechanism possible to browse the pause menu......... If that is not possible in some case, have in mind that resetting cursors, pointers, etc. between different UI elements ,, might help you on the way you are going... In this particular case , as long as we can't see the code behind pauseMenuUi
, i think the mistake lies somewhere in this script....
Your answer
