- 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.
推薦閱讀
- 深入理解Bootstrap
- JavaScript Unlocked
- 看透JavaScript:原理、方法與實踐
- Android 7編程入門經典:使用Android Studio 2(第4版)
- Web全棧工程師的自我修養
- C++程序設計基礎教程
- Azure Serverless Computing Cookbook
- 汽車人機交互界面整合設計
- 智能手機故障檢測與維修從入門到精通
- Java Web應用開發項目教程
- Android Development Tools for Eclipse
- Xamarin Blueprints
- Practical Maya Programming with Python
- 從零開始:C語言快速入門教程
- Monitoring Docker