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

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.

主站蜘蛛池模板: 集安市| 三河市| 崇义县| 内乡县| 淮北市| 宜黄县| 舒城县| 肇东市| 光泽县| 阿荣旗| 玛多县| 边坝县| 亚东县| 湘乡市| 宁国市| 和田县| 邛崃市| 宁化县| 辰溪县| 香河县| 阳江市| 玉田县| 兴业县| 通榆县| 鹤山市| 扎鲁特旗| 喜德县| 武宁县| 兰州市| 温宿县| 沧源| 吴江市| 古蔺县| 滨州市| 蕉岭县| 武山县| 昂仁县| 昌黎县| 苏州市| 长春市| 长岛县|