0
votes

I am trying to create a pause menu within my FPS game. However, when the game is paused, whenever I mouse over any of the buttons that appear I cannot click on them. I've tried disabling my FPS controller (I'm using the unity fps controller provided) script and checked my canvas has an event system etc. Any suggestions would be a huge help! Here is my code for the pause menu I have :


    public Transform menu;
    public GameObject Player;
    public GameObject Gun;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Pause();
        }
    }

    public void Pause()
    {
        if (menu.gameObject.activeInHierarchy == false)
        {
            menu.gameObject.SetActive(true);
            Time.timeScale = 0;
            Gun.GetComponent<Gun>().enabled = false;
            Player.GetComponent<FirstPersonController>().enabled = false;
            Cursor.lockState = CursorLockMode.None;
            Cursor.lockState = CursorLockMode.Confined;
            Cursor.visible = true;
        }
        else
        {
            menu.gameObject.SetActive(false);
            Time.timeScale = 1;
            Player.GetComponent<FirstPersonController>().enabled = true;
            Gun.GetComponent<Gun>().enabled = true;
        }
    }

    public void QuitToMain()
    {
        SceneManager.LoadScene("Menu 3D");
    }
} ```
1

1 Answers

0
votes

Does the pause menu work outside of the games pause state? Have you checked whether the buttons are obstructed by other UI objects that are in the way?

This link might help you to debug the UI issues:

https://answers.unity.com/questions/1148727/ui-button-not-working-2.html