64 lines
1.2 KiB
C#
64 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MenuController : MonoBehaviour
|
|
{
|
|
public static MenuController Instance { get; private set; }
|
|
|
|
public GameObject pauseMenuPanel;
|
|
public Button resumeButton;
|
|
public Button quitButton;
|
|
|
|
public bool isPaused = false;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else if (Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
resumeButton.onClick.AddListener(TogglePause);
|
|
quitButton.onClick.AddListener(CloseGame);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
TogglePause();
|
|
}
|
|
}
|
|
void TogglePause()
|
|
{
|
|
isPaused = !isPaused;
|
|
pauseMenuPanel.SetActive(isPaused);
|
|
|
|
if (isPaused)
|
|
{
|
|
Time.timeScale = 0f;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
}
|
|
else
|
|
{
|
|
Time.timeScale = 1f;
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void CloseGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|