问题描述
昨天我将unity5的unity更新为2018.2.2f1.在Update 2018.2.2f1之后不会加载Unity脚本.
Yesterday I updated unity from unity5 to 2018.2.2f1. Unity scripts are not loading after Update 2018.2.2f1.
一旦我尝试播放场景,脚本将不会加载,并且我无法再次添加脚本,则会出现此错误:
Once I try to play the Scene the scripts are not loaded and I can't add the script again it gives this error:
推荐答案
如果您仍然拥有项目的旧副本,请先将Unity项目升级到 Unity 2017 ,然后再升级到 2018.2. 2f1 .
If you still have the old copy of the project, upgrade the Unity project to Unity 2017 first then to 2018.2.2f1.
以下是您可能会收到此错误的几种可能原因(很有可能是顺序原因)
Here are the few possible reasons you may get this error(Ordered from very likely)
1 .脚本名称与类名称不匹配.
1.Script name does not match class name.
如果脚本名称为MyClass
,则类名称必须为MyClass
.这也是区分大小写的.仔细检查以确保这不是问题.为确保不是问题,请复制类名称并将其粘贴为脚本名称,以确保这不是问题.
If script name is called MyClass
, the class name must be MyClass
. This is also case-sensitive. Double check to make sure that this is not the issue. To make sure that's not the issue, copy the class name and paste it as the script name to make sure that this is not the issue.
请注意,如果一个脚本中有多个类,则应与脚本名称匹配的类名称是从MonoBehaviour
派生的类.
Note that if you have have multiple classes in one script, the class name that should match with the script name is the class that derives from MonoBehaviour
.
2 .您的脚本中有错误.由于这是一次升级,因此您有可能正在使用现已弃用并删除的API.使用Visual Studio打开脚本,然后查看是否存在错误,然后对其进行修复.在代码下通常会出现一条红线,表明存在错误.
2.There is an error in your script. Since this is an upgrade, there is a chance you're using an API that is now deprecated and removed. Open your script with Visual Studio and see if there is an error there then fix it. There is usually a red line under a code that indicates there is an error.
3 .使用Unity导入器及其自动升级脚本进行错误导入.
3.Bad import with the Unity importer and its automatic upgrade script.
尝试的事情:
A .首先要做的是重新启动Unity Editor.
A.The first thing to do is restart the Unity Editor.
B .右键单击项目"选项卡,然后单击"全部重新导入"
B.Right click on the Project Tab then click "Reimport All"
C .如果仍然存在问题,剩下的就是删除有问题的脚本并创建一个新脚本.如果脚本已附加到场景中的许多GameObject,则有一种更简单的方法.
C.If there is still issue, the only left is deleting the problematic script and creating a new one. There is an easier way to do this if the script is attached to many GameObjects in your scene.
A .打开脚本,将其内容复制到记事本中.
A.Open the script, copy its content into notepad.
B .在编辑器中,在 Project 选项卡上,右键单击脚本"CubeScript",选择在场景中查找引用" .
B.From the Editor and on the Project tab right click on the script "CubeScript", select "Find References In Scene".
C .Unity现在仅显示所有已附加此脚本的GameObject.删除旧脚本.创建一个新的脚本,然后将内容从记事本复制到该新脚本.现在,您只需将新脚本拖到场景中所有已过滤的GameObject上即可.对每个受影响的脚本执行此操作.这是一项手动工作,但是完成后应该可以解决您的问题.
C.Unity will now only show all the GameObjects that has this script attached to them. Delete the old script. Create a new one then copy the content from the notepad to this new script. Now, you can just drag the new script to all the filtered GameObject in the scene. Do this for every script effected. This is a manual work but should fix your issues when completed.
这篇关于无法添加脚本组件,因为找不到脚本类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!