how to make it so you have to press a button twice

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;
    }
}

You mentioned you have a pop-up menu and a button. With the code above, whenever the mouse button is held down, the LockCursor() routine is called. In fact, it will be called multiple times because it will be called on every frame that the user is holding the button down. This will also happen if you are trying to click a button. So you’ll need to disable this script (or at least the lockCursor() part) if you want the mouse button to do anything else.