Closing the pause-menu

Hi! I want to make the resume-button to close the pausemenu. How do I do fix it?

This is what the pausemenu looks like:

Here are my scripts:

PauseHandlerScript:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseHandlerScript : MonoBehaviour
{
    // Start is called before the first frame update

    public bool paused = false;

    public GameObject pauseMenu;

    void Start()
    {
        pauseMenu.GetComponent<PauseMenuScript>();
    }

    // Update is called once per frame
    void Update()
    {

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            paused = !paused;
        }
        if (paused)
        {
            Time.timeScale = 0;
            pauseMenu.SetActive(paused);
            AudioListener.pause = true;

        }
        else
        {
            Time.timeScale = 1;
            pauseMenu.SetActive(paused);
            AudioListener.pause = false;
        }
    }

    public void ClosePauseMenu()
    {
        pauseMenu.SetActive(false);
        Time.timeScale = 0;
    }
}

PauseMenuScript:

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PauseMenuScript : MonoBehaviour
{
    [SerializeField] GameObject pauseMenu;
    public TextMeshProUGUI titleText;
    public Button resumeButton;

    public bool pauseBool = false;

    // Start is called before the first frame update
    void Start()
    {
        gameObject.SetActive(pauseBool);

    }

    // Update is called once per frame
    void Update()
    {

    }


    public void ActivePauseMenu()
    {
        pauseMenu.SetActive(true);
    }

    public void ClosePauseMenu()
    {
        pauseMenu.SetActive(false);
    }

}

When I added the canvas on the OnClick-function the resume-button does not work when I select Function, PauseHandlerScript and ClosePauseMenu () to close down the pausemenu.



Hello, your question is not really accessibility related, it’s general programming.

The answer though is that if you want to unpause/resume through the button, you need to make sure that when you click it, exactly the same logic you used on your Update function also runs: set the correct value for the paused variable, set the time scale to 1 (not zero, since you’re unpausing/resuming), and don’t forget to reactivate your AudioListener!

Highly recommend separating this logic in its own method so you can always run the same logic, either in the Update because of the key press, or in the button click logic.

Hope this helps :slight_smile:

I wrote the time scale to 1, but I don’t know how I should seperate the logic in its own method.