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

Inheritance

Unity components inherit from MonoBehaviour and that is what makes the code that we are creating work inside Unity and not in other C# applications. For beginners to Unity, studying C# inheritance isn't a subject you need to learn in any great detail, but you do need to know that each Unity script uses inheritance. We see the code in every script that will be attached to a GameObject. In variableScript, the code is on line 4:

public class variableScript : MonoBehaviour 

The colon and the last word of this code mean that the variableScript class is inheriting behaviors from the MonoBehaviour class. This simply means that the MonoBehaviour class is making a few of its variables and methods available to the variableScript class. It's no coincidence that the variables and methods inherited look like some of the code that we saw in the Unity Scripting Reference.

The following are the two inherited behaviors in the variableScript class:

Line 10: void Start () 
Line 15: void Update () 

You don't have to call these methods; Unity calls them behind the scenes. So, the code that you place in these methods gets executed automatically.

主站蜘蛛池模板: 云浮市| 咸丰县| 大化| 新巴尔虎左旗| 武强县| 正阳县| 临猗县| 曲阜市| 乌兰县| 东兴市| 贵德县| 合水县| 法库县| 德惠市| 清水河县| 临朐县| 荥阳市| 德庆县| 凤山县| 千阳县| 额敏县| 武安市| 西吉县| 开阳县| 循化| 六安市| 冕宁县| 沾益县| 筠连县| 东平县| 准格尔旗| 马龙县| 长葛市| 隆德县| 炎陵县| 灵寿县| 孟津县| 永平县| 公主岭市| 泰兴市| 五指山市|