我从 Unity 开始,只是为简历菜单编写了代码,但我不知道如何使其有效。
这是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResumeMenu : MonoBehaviour
{
public GameObject pauseMenu;
public bool isPaused;
void Start()
{
pauseMenu.SetActive(false);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (isPaused)
{
ResumeGame();
}
else
{
PauseGame();
}
}
}
public void PauseGame()
{
pauseMenu.SetActive(true);
Time.timeScale = 0f;
isPaused = true;
}
public void ResumeGame()
{
pauseMenu.SetActive(false);
Time.timeScale = 1f;
isPaused = false;
}
}
我不知道把脚本放在哪里,所以菜单只能在游戏中使用。我尝试观看一些视频,大多数使用一些游戏管理器