"The type or namespace name could not be found. Are you missing assembly reference ?" Unity 错误

"The type or namespace name could not be found. Are you missing assembly reference ?" Error in Unity

我试图在鼠标悬停在对象上时显示 GUI 标签,而当鼠标光标从对象上移开时标签隐藏。

谁能告诉我为什么会出现错误?

using UnityEngine;
using System.Collections;

public class label_diet : MonoBehaviour {
    public showGUI boolean = false;
    void OnMouseOver()
    {
        showGUI = true;
    }

    void OnMouseExit()
    {
        showGUI = false;
    }

    void OnGUI()
    {
        if (showGUI)
        {
            GUI.Label(new Rect(10, 10, 100, 20), "You are selecting Diet coke");
        }
    }
}

请检查此引用 UnityEngine。如果您使用的是 dll,请检查 dll 版本或检查其所有依赖项(如果包含在您的项目中)。

希望对您有所帮助..

更改显示为

的行
public showGUI boolean = false;

public bool showGUI = false; //for C#
public var showGUI = false; //for JS, but you're using C#

那应该没问题;如果不是,请检查脚本是否附加到 UI 对象或具有碰撞器组件的对象。