- Learning C# 7 By Developing Games with Unity 2017(Third Edition)
- Micael DaGra?a Greg Lukosek
- 153字
- 2021-07-02 19:59:34
Watching for possible gotchas while creating script files in Unity
Notice line 4 in the following screenshot:

public class LearningScript : MonoBehaviour
The class name LearningScript is the same as the filename LearningScript.cs. This is a requirement. You probably don't know what a class is yet, but that's okay. Just remember that the filename and the class name must be the same.
When you create a C# script file in Unity, the filename in the Project tab is in Edit mode, ready to be changed. Please rename it right then and there. If you rename the script later, the filename and the class name won't match. The filename would change, but line 4 will be this:
public class NewBehaviourScript : MonoBehaviour
This can easily be fixed in MonoDevelop by changing NewBehaviourScript in line 4 to the same name as the filename, but it's much simpler to do the renaming in Unity immediately.
推薦閱讀
- 小程序實戰視頻課:微信小程序開發全案精講
- Learning Spring 5.0
- 軟件界面交互設計基礎
- VSTO開發入門教程
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優化計算
- Building an RPG with Unity 2018
- Ext JS 4 Web Application Development Cookbook
- Python忍者秘籍
- Julia高性能科學計算(第2版)
- INSTANT Yii 1.1 Application Development Starter
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- Mudbox 2013 Cookbook
- Python應用與實戰
- Drupal Search Engine Optimization
- SQL Server on Linux