Files
Dontback/Assets/Scripts/UI/PauseButton.cs
Eicy c9d29f2a68 AI补足注释(已经快看不懂了)
实现i18n
优化部分模块的逻辑以优化性能
修复物品展示框打开时按下ESC唤出暂停菜单但没有暂停的bug

Signed-off-by: Eicy <im@crash.work>
2024-10-14 21:37:04 +08:00

35 lines
1.0 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 UnityEngine;
namespace UI
{
// 控制暂停按钮的类
public class PauseButton : MonoBehaviour
{
[SerializeField] private GameObject pauseMenu; // 暂停菜单的游戏对象
private void Update()
{
// 检测是否按下 Escape 键并且游戏未暂停
if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale != 0)
{
Pause(); // 调用暂停方法
UnlockCursor(); // 解锁鼠标光标
}
}
// 暂停游戏的方法
public void Pause()
{
pauseMenu.SetActive(true); // 显示暂停菜单
Time.timeScale = 0; // 将时间缩放设置为 0暂停游戏
gameObject.SetActive(false); // 隐藏暂停按钮
}
// 解锁鼠标光标的方法
private void UnlockCursor()
{
Cursor.lockState = CursorLockMode.None; // 设置光标状态为解锁
Cursor.visible = true; // 确保光标可见
}
}
}