找不到脚本类,无法添加脚本组件? [英] Can't add script component because the script class cannot be found?

查看:982
本文介绍了找不到脚本类,无法添加脚本组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我把unity从unity5更新到了2018.2.2f1.更新 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:

无法添加脚本组件CubeScript",因为脚本类找不到.确保没有编译错误并且文件名和类名匹配.

Can't add script component 'CubeScript' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

推荐答案

如果您还有项目的旧副本,请先将 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 编辑器.

A.The first thing to do is restart the Unity Editor.

B.右键单击项目"选项卡,然后单击全部重新导入"

B.Right click on the Project Tab then click "Reimport All"

C.如果问题仍然存在,唯一剩下的就是删除有问题的脚本并创建一个新脚本.如果脚本附加到场景中的许多游戏对象,则有一种更简单的方法可以做到这一点.

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.在编辑器和项目选项卡上右键单击脚本CubeScript",选择Find References In Scene".

B.From the Editor and on the Project tab right click on the script "CubeScript", select "Find References In Scene".

C.Unity 现在将仅显示附加了此脚本的所有游戏对象.删除旧脚本.创建一个新脚本,然后将记事本中的内容复制到这个新脚本中.现在,您只需将新脚本拖动到场景中所有过滤的 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.

这篇关于找不到脚本类,无法添加脚本组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆