【问题标题】:I am trying to build my game in unity but it is giving me an error我正在尝试统一构建我的游戏,但它给了我一个错误
【发布时间】:2014-11-18 07:14:19
【问题描述】:

Assets/Scripts/ThirdPersonCamera.cs(3,7):错误 CS0246:找不到类型或命名空间名称“UnityEditor”。您是否缺少 using 指令或程序集引用?

我很困惑为什么我会收到这个错误.....

为什么会这样?

【问题讨论】:

  • 您似乎缺少参考资料。
  • 试试 UnityEngine
  • 在此处查看第二个答案:answers.unity3d.com/questions/316805/… 听起来您无法使用任何特定于编辑器的脚本来构建游戏。
  • @MyCodeSucks 很可能他并没有错过参考。 “UnityEditor”命名空间在构建中根本不可用。

标签: c# unity3d


【解决方案1】:

这是因为 UnityEditor 命名空间仅在位于 Assets/Editor 文件夹中的编辑器脚本中可用;或者如果您在编辑器中运行游戏。如果您在编辑器中运行游戏时需要一些功能,可以这样做:

#if UNITY_EDITOR
using UnityEditor;
#endif

class Script: MonoBehaviour {
    void Update() {
#if UNITY_EDITOR
        // Editor specific part here
#endif
    }
}

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2020-09-02
    相关资源
    最近更新 更多