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.