im making a retro fps game and i have code to hide the mouse while playing and press space to bring it back up then just press mouse to hide it again but when the try again menu pops up when you try to press the try again button it doesnt respond and immediately hides mouse how can i fix this here is code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
LockCursor();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
UnlockCursor();
}
if(Input.GetMouseButton(0))
{
LockCursor();
}
}
private void LockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void UnlockCursor()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}