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

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.

主站蜘蛛池模板: 井冈山市| 云梦县| 凤台县| 陕西省| 灌云县| 宁河县| 漳州市| 丰宁| 池州市| 玛纳斯县| 德庆县| 清涧县| 商南县| 博乐市| 繁昌县| 绥化市| 遂宁市| 西乌珠穆沁旗| 铜梁县| 商城县| 钟祥市| 孟津县| 沾化县| 蓬溪县| 瑞安市| 原平市| 马尔康县| 陆川县| 泰宁县| 囊谦县| 靖江市| 瑞安市| 安庆市| 绥化市| 台湾省| 方正县| 福建省| 郁南县| 雅安市| 霍州市| 鸡东县|