Need help with pause menu and cursor lock script conflict
The specific issue I am having is that I locked my cursor to the screen and made it invisible (see script below)
// to lock and hide the mouse cursor in-game
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
This script worked fine, however I have just added a Pause Menu to my project and if I try to use that Menu with this script my cursor will re-appear and unlock. however, every time that I click the screen it locks and hides the cursor again and my Menu buttons are not able to be pressed.
I have been trying to add some thing like this;
if (Input.GetKey(KeyCode.Escape))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
To see if I can get functionality back to my cursor during the pause menu. I am only a month in with Unity and C# and really need a push in the right direction.
Answer by Zoedingl · Jun 22, 2020 at 11:43 AM
public boolean isPaused = false;
void Update()
{
if (!isPaused)
{
//Lock and hide the cursor
//Do some game stuff
}
else
{
//Unlock Cursor
}
if (Input.GetKeyDown(KeyCode.Escape))
{
if (isPaused) {
//Resume the game and lock cursor
}
else
{
//Pause the game
//unlock cursor
}
}
}
Thank you! This has been an annoying roadblock in coding my game and I can't thank you enough!