Unity UI暂停菜单预制体(Prefab)跨场景使用时按钮失效问题求助
Unity UI暂停菜单预制体(Prefab)跨场景使用时按钮失效问题求助
我遇到一个奇怪的问题:把UI做成预制体后,所有按钮都失效了,完全点不动。我是跟着Brackeys的教程做的暂停菜单,在最初创建它的那个场景里,哪怕做成预制体也能正常工作,但放到其他场景里的副本全坏了。有没有大佬知道这是啥原因啊?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Audio; public class PauseMenu : MonoBehaviour { public static bool GameIsPaused = false; public GameObject PauseUI; public GameObject OptionsUI; public AudioMixer audioMixer; // Start is called before the first frame update void Start() { PauseUI.SetActive(false); OptionsUI.SetActive(false); Cursor.visible = false; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (GameIsPaused) { Resume(); } else { Pause(); } } } public void Resume() { PauseUI.SetActive(false); Time.timeScale = 1f; GameIsPaused = false; Cursor.visible = false; } private void Pause () { PauseUI.SetActive(true); Time.timeScale = 0f; GameIsPaused = true; Cursor.visible = true; } public void QUITOnClick() { Debug.Log("You have clicked the button!"); Application.Quit(); } public void Options() { PauseUI.SetActive(false); OptionsUI.SetActive(true); } public void Back() { PauseUI.SetActive(true); OptionsUI.SetActive(false); } public void SetVolume(float volume) { audioMixer.SetFloat("volume", volume); } }
我试过重新添加EventSystem,也重新关联过脚本,但这些方法都没解决问题。
备注:内容来源于stack exchange,提问作者user28003022
相关产品推荐
相关产品推荐

