Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How do I make the pausemenu close when pressing the resumebutton?

Discussion in 'UGUI & TextMesh Pro' started by mr_pineapple_44, Oct 10, 2023.

  1. mr_pineapple_44

    mr_pineapple_44

    Joined:
    Aug 18, 2023
    Posts:
    3
    I've created a ResumeButton-method in PauseMenuScript that can close the pausemenu, but it didn't work. What do I do instead?

    These are my scripts:

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

    public void ResumeButton()
    {
    if (resumeButton.interactable)
    {
    pauseMenu.SetActive(false);
    }
    }

    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>().ActivePauseMenu();
    }

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



    }
    }

    Here is what it look like in Unity.

    buttonhelp1.PNG
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
  3. mr_pineapple_44

    mr_pineapple_44

    Joined:
    Aug 18, 2023
    Posts:
    3
    Ok, thanks!