PacMan/Assets/Scripts/PauseManager.cs
2025-03-17 21:56:02 +08:00

58 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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