前言
在Unity开发中,会出现一些报错,这次总结一下本人在开发中的常见错误,并跟随其解决方案,以便之后好进行回顾。
编译错误
1.1 错误信息:“The type or namespace name ‘XXX’ could not be found (are you missing a using directive or an assembly reference?)”
原因:这个错误通常是因为缺少命名空间或程序集引用导致的
解决方法如下:
检查代码中是否缺少using语句,如缺少,添加对应的命名空间即可。
检查是否缺少程序集引用,如缺少,在项目的引用中添加对应的程序集即可。
**1.2 “Assets/Scripts/XXX.cs(1,1): error CS0246: The type or namespace name ‘XXX’ could not be found (are you missing a using directive or an assembly reference?)” **
原因:这个错误通常是因为脚本中引用了未被识别的类或命名空间导致的。
解决方法: 检查代码中是否存在拼写错误或语法错误。
检查脚本中引用的类或命名空间是否正确,如不正确,修改为正确的类或命名空间即可。
运行时错误
2.1 “NullReferenceException: Object reference not set to an instance of an object”
原因:这个