- 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.
推薦閱讀
- GAE編程指南
- Reporting with Visual Studio and Crystal Reports
- Mastering OpenCV 4
- Ext JS 4 Web Application Development Cookbook
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實(shí)戰(zhàn)全流程詳解(入門與提高篇)
- 從Java到Web程序設(shè)計(jì)教程
- 好好學(xué)Java:從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- 深入理解C指針
- Instant Automapper
- 微信小程序開發(fā)邊做邊學(xué)(微課視頻版)
- 零基礎(chǔ)學(xué)編程系列(全5冊(cè))
- Python Penetration Testing Essentials
- 面向物聯(lián)網(wǎng)的Android應(yīng)用開發(fā)與實(shí)踐
- JavaScript程序設(shè)計(jì)基礎(chǔ)教程(慕課版)
- Switching to Angular 2