77 lines
1.5 KiB
C#
77 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class PauseMenu : MonoBehaviour
|
|
{
|
|
public static bool IsPaused = false;
|
|
|
|
[SerializeField] InputMaster inputAction;
|
|
[SerializeField] GameObject pauseMenu;
|
|
|
|
private void Awake()
|
|
{
|
|
inputAction = new InputMaster();
|
|
inputAction.Menu.Pause.performed += _ => ExecutePauseUnpause();
|
|
}
|
|
|
|
private void ExecutePauseUnpause()
|
|
{
|
|
Debug.Log("ExecutePauseUnpause");
|
|
if (IsPaused)
|
|
ResumeGame();
|
|
else
|
|
PauseGame();
|
|
}
|
|
|
|
|
|
private void OnEnable()
|
|
{
|
|
inputAction.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
inputAction.Disable();
|
|
}
|
|
|
|
void PauseGame()
|
|
{
|
|
Time.timeScale = 0f;
|
|
IsPaused = true;
|
|
pauseMenu.SetActive(true);
|
|
}
|
|
|
|
public void ResumeGame()
|
|
{
|
|
Time.timeScale = 1f;
|
|
IsPaused = false;
|
|
pauseMenu.SetActive(false);
|
|
}
|
|
|
|
public void LoadMenu()
|
|
{
|
|
Time.timeScale = 1f;
|
|
IsPaused = false;
|
|
SoundManager.Instance.SwitchMusicLayer(-1);
|
|
SceneManager.LoadScene(0);
|
|
}
|
|
|
|
public void RestartGame()
|
|
{
|
|
Time.timeScale = 1f;
|
|
IsPaused = false;
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
Debug.Log("QuitGame");
|
|
Application.Quit();
|
|
}
|
|
|
|
|
|
}
|