首页 > 解决方案 > Unity UI 未在脚本中将可交互性设置为 true

问题描述

我以前也遇到过这个问题,现在受不了了。为什么以及如何发生这种情况?我是 C# 新手,我不知道我做错了什么。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ButtonActivate : MonoBehaviour
{
    bool Test;
    Button ButtonHere;
    void Update()
    {
        Test = true;
        if (Test == true)
        {
            ButtonHere.interactable = true;
        }
    }
}

标签: unity3d

解决方案


我能想到的两个可能的错误是:

  • Buttonhere 正在null或正在引用错误的游戏对象。

  • 该脚本未附加到任何东西,请尝试将其附加到按钮本身或“主摄像头”之类的东西上。


推荐阅读