官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 中西区| 肇庆市| 武胜县| 府谷县| 东莞市| 内黄县| 乌鲁木齐市| 凤阳县| 祥云县| 饶河县| 广河县| 成武县| 清原| 苍山县| 合作市| 朔州市| 赤水市| 江孜县| 岳普湖县| 浪卡子县| 新建县| 慈利县| 阿鲁科尔沁旗| 合水县| 左权县| 石柱| 承德县| 寿阳县| 伊吾县| 拉萨市| 山西省| 吉木萨尔县| 蓬安县| 思南县| 老河口市| 博兴县| 定襄县| 西青区| 南部县| 垣曲县| 阳山县|