58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.UI;
|
||
|
||
public class PauseManager : MonoBehaviour
|
||
{
|
||
|
||
public PacManInput pacManInputControl;//输入系统
|
||
|
||
public GameObject PauseMenu;
|
||
public GameObject PauseButton;
|
||
public Sprite[] pauseSprite;
|
||
private bool isPaused = false;
|
||
|
||
private void Awake()
|
||
{
|
||
pacManInputControl = new PacManInput();//new一个新的输入系统
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
pacManInputControl.Enable();
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
pacManInputControl.Disable();
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
// 可选:增加键盘快捷键(如ESC键)
|
||
pacManInputControl.PacManInputSystem.Menu.performed += ctx => TogglePause();
|
||
}
|
||
|
||
// 按钮点击事件绑定方法
|
||
public void TogglePause()
|
||
{
|
||
isPaused = !isPaused;
|
||
PauseMenu.SetActive(isPaused);
|
||
PauseButton.gameObject.GetComponent<Image>().sprite = isPaused ? pauseSprite[0] : pauseSprite[1];
|
||
Time.timeScale = isPaused ? 0 : 1;
|
||
}
|
||
|
||
public void RestartGame()
|
||
{
|
||
Time.timeScale = 1;
|
||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||
}
|
||
|
||
public void QuitGame()
|
||
{
|
||
Application.Quit();
|
||
}
|
||
}
|