Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从pausescreen C中选择菜单#_C#_Unity3d_Time - Fatal编程技术网

C# 从pausescreen C中选择菜单#

C# 从pausescreen C中选择菜单#,c#,unity3d,time,C#,Unity3d,Time,在这段代码中,我确实创建了一个带有一些按钮的暂停菜单,如resume和menu。如果我点击菜单,我会进入菜单,但时间仍然冻结,如果我再次按escape,我可以继续玩游戏。为什么会这样。如果你按menu,我会进入菜单,它会激活Resume方法。如果我只按resume,resume方法可以正常工作,但当我单击菜单时,该方法不起作用 using System.Collections; using System.Collections.Generic; using UnityEngine

在这段代码中,我确实创建了一个带有一些按钮的暂停菜单,如resume和menu。如果我点击菜单,我会进入菜单,但时间仍然冻结,如果我再次按escape,我可以继续玩游戏。为什么会这样。如果你按menu,我会进入菜单,它会激活Resume方法。如果我只按resume,resume方法可以正常工作,但当我单击菜单时,该方法不起作用

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class PauseMenu : MonoBehaviour
    {
    
        public static bool GameIsPaused = false;
    
        public GameObject pauseMenuUI;
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (GameIsPaused)
                {
                    Resume();
                }
                else
                {
                    Pause();
                }
            }
        }
    
        public void Menu()
        {
            Resume();
            SceneManager.LoadScene(0);
        }
    
        public void Resume()
        {
            pauseMenuUI.SetActive(false);
            Time.timeScale = 1f;
            GameIsPaused = false;
        }
    
        public void Pause()
        {
            pauseMenuUI.SetActive(true);
            Time.timeScale = 0f;
            GameIsPaused = true;
        }
    }

当我单击“菜单”时,我已尝试将服务器时间刻度设置为正常,但时间刻度仍然为0,因此您必须再次在“暂停”菜单中单击“恢复”,并且时间刻度再次正确,但这不是它应该如何工作的。

代码应该工作,但您是否将脚本设置为“暂停”菜单画布?如果是这样,还需要在inspector中的每个按钮上设置一个
OnClick()
事件

希望这能奏效