You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:44:35