C# 为什么我的暂停菜单脚本只工作一次?SetActive仅使用false
我想知道为什么我的暂停脚本不能按预期工作。它应该冻结时间并打开“暂停”菜单,但它只会冻结,之后什么也不会发生。我也不能继续比赛了C# 为什么我的暂停菜单脚本只工作一次?SetActive仅使用false,c#,unity3d,C#,Unity3d,我想知道为什么我的暂停脚本不能按预期工作。它应该冻结时间并打开“暂停”菜单,但它只会冻结,之后什么也不会发生。我也不能继续比赛了 using System.Collections; using System.Collections.Generic; using System.Threading; using UnityEngine; public class PauseMenu : MonoBehaviour { // Start is called before the first
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
public class PauseMenu : MonoBehaviour
{
// Start is called before the first frame update
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
}SetActive(false)
将禁用游戏对象,即它将不再更新。因此,如果您的pauseMenuUI
是您在其上调用的对象(或它的后代),那么您的脚本将不再被调用
解决方案是将脚本放在另一个对象(例如pauseMenuUI`)上