简体   繁体   English

如何统一修复“找不到类型或命名空间名称”错误?

[英]How to fix 'The type or namespace name could not be found ' error in unity?

I am setting up a new scriptable object in Unity 5 and when I am trying to set up a reference to it an error shows up:'The type or namespace name 'ES' could not be found (are you missing a using directive or an assembly reference?'我在 Unity 5 中设置了一个新的可编写脚本的 object,当我尝试设置对它的引用时,出现错误:'找不到类型或命名空间名称'ES'(您是否缺少 using 指令或装配参考?

the scriptable object script:可编写脚本的 object 脚本:

 using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(fileName = "new ES", menuName = "ES")] public class LAMP: ScriptableObject { public int groupNum; void Start() { groupNum = 1; } }

the reference in monobehavior script: monobehavior 脚本中的参考:

 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bout: MonoBehaviour { public ES et; // Use this for initialization void Start() { } // Update is called once per frame void Update() { } }

It is a name space error,if you are using a collision variable you face this error.这是一个名称空间错误,如果您使用冲突变量,您将面临此错误。

Using My.Players.namespace;使用 My.Players.namespace;

In your file Bout.cs you are trying to create the variable 'et' of type ES but the type ES doesn't exist, you may want to create a LAMP?在您的文件 Bout.cs 中,您尝试创建 ES 类型的变量“et”,但 ES 类型不存在,您可能想要创建 LAMP?

 public class Bout: MonoBehaviour { public LAMP et; // Use this for initialization void Start() {

Creating a scriptable object file named ES (fileName = "new ES") doesn't mean it's type is ES, it takes the type of the class ie LAMP创建一个名为 ES (fileName = "new ES") 的可编写脚本的 object 文件并不意味着它的类型是 ES,它采用 class 的类型,即 LAMP

I have encountered the same error while trying to add script component to the gameobject on runtime.我在运行时尝试将脚本组件添加到游戏对象时遇到了同样的错误。 Fixed it by following this format:通过以下格式修复它:

 GameObject.AddComponent(typeof(namespace.className));

The meaning of The type or namespace name 'xxxx' could not be found is because you are trying to use a class that do not exist or you are not using the namespace where that class is. The The type or namespace name 'xxxx' could not be found的含义是因为您尝试使用不存在的 class,或者您没有使用 class 所在的命名空间。

The problem that you have is that you are trying to use something that do not exists.您遇到的问题是您正在尝试使用不存在的东西。

You are trying to create a scriptable object named ES, but it's totally different to create a class named ES.您正在尝试创建一个名为 ES 的可编写脚本的 object,但创建一个名为 ES 的 class 完全不同。

If you create the class ES you will see that the error goes away.如果您创建 class ES,您将看到错误消失。

Just had this error and this is the top SO post about it, so I'll post my fix here:刚刚遇到这个错误,这是关于它的顶级 SO 帖子,所以我将在这里发布我的修复:

We introduced unit tests, which require the .asmdef for each "group" of related scripts.我们引入了单元测试,它要求每个“组”相关脚本都有.asmdef In this particular instance for us, the original developer had the .asmdef file for scripts that were contained in an AutoGenerated folder (ROS messages) that was set to be ignored by Git.在我们这个特定的例子中,原始开发人员拥有一个包含在自动生成文件夹(ROS 消息)中的脚本的.asmdef文件,该文件夹被设置为被 Git 忽略。

He pushed the code, Git ignored the .asmdef file for the AutoGenerated files, and then because we were using .asmdef files and that folder wasn't included on MY box, my Unity "couldn't find" the files there.他推送了代码,Git 忽略了 AutoGenerated 文件的.asmdef文件,然后因为我们使用的是.asmdef文件并且该文件夹未包含在我的盒子中,我的 Unity “找不到”那里的文件。

This could be your problem, too, but 99 times out of 100 you get this error because you've misspelled the class name - capitalization matters In OP's case specifically the actual class is LAMP even though it's called ES in the AssetMenu.也可能是您的问题,但是 100 次中有 99 次出现此错误,因为您拼错了 class 名称 - 大写很重要 在 OP 的情况下,特别是实际的 class 是LAMP ,即使它在 AssetMenu 中被称为ES Instead of public ES et;而不是public ES et; OP should have had public LAMP et; OP 应该有public LAMP et; and then it would work.然后它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unity 构建错误:找不到类型或命名空间名称“Editor” - Unity build error: The type or namespace name 'Editor' could not be found 找不到类型或命名空间名称“NUnit”| 统一 - The type or namespace name 'NUnit' could not be found | Unity Unity:找不到类型或名称空间名称“功能” - Unity: The type or namespace name 'function' could not be found 找不到类型或命名空间名称 Unity - The type or namespace name could not be found Unity '找不到类型或命名空间名称'如何在Unity中解决 - 'The type or namespace name could not be found ' how to solve in Unity 如何修复:找不到类型或命名空间名称“MouseLook” - How to fix: The type or namespace name 'MouseLook' could not be found 如何修复“无法找到类型或命名空间名称”? - How do I fix “The type or namespace name could not be found”? "Unity 包错误“找不到命名空间的类型”" - Unity Package Error "the type of namespace could not be found" 找不到类型或命名空间名称“ScriptName”(您是否缺少 using 指令或程序集引用?)修复 unity c# - The type or namespace name 'ScriptName' could not be found (are you missing a using directive or an assembly reference?) fix unity c# 如何解决 AssetBundle 上的“找不到类型或命名空间名称”错误 - How to solve the error “type or namespace name could not be found” on AssetBundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM