You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.0 KiB
49 lines
1.0 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PauseMenu : MonoBehaviour
|
|
{
|
|
public GameObject pauseMenuUI; // 拖放你的菜单面板
|
|
|
|
void Update()
|
|
{
|
|
// 检测 ESC 键按下
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
// 切换菜单显示状态
|
|
if (pauseMenuUI.activeSelf)
|
|
{
|
|
Resume();
|
|
}
|
|
else
|
|
{
|
|
Pause();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Resume()
|
|
{
|
|
pauseMenuUI.SetActive(false); // 隐藏菜单
|
|
Time.timeScale = 1f; // 恢复时间
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
pauseMenuUI.SetActive(true); // 显示菜单
|
|
Time.timeScale = 0f; // 暂停时间
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
// 在编辑器中退出游戏,或在构建版本中退出
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorApplication.isPlaying = false; // 在编辑器中退出
|
|
#else
|
|
Application.Quit(); // 在构建中退出
|
|
#endif
|
|
}
|
|
}
|
|
|