- Learning C# 7 By Developing Games with Unity 2017(Third Edition)
- Micael DaGra?a Greg Lukosek
- 195字
- 2021-07-02 19:59:38
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.
- Visual C++程序設(shè)計學(xué)習(xí)筆記
- 移動UI設(shè)計(微課版)
- Python從菜鳥到高手(第2版)
- 從0到1:HTML+CSS快速上手
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優(yōu)化計算
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- Spring核心技術(shù)和案例實(shí)戰(zhàn)
- 微服務(wù)從小白到專家:Spring Cloud和Kubernetes實(shí)戰(zhàn)
- Learning R for Geospatial Analysis
- 遠(yuǎn)方:兩位持續(xù)創(chuàng)業(yè)者的點(diǎn)滴思考
- Mastering Gephi Network Visualization
- Java 9 with JShell
- Raspberry Pi Robotic Projects
- C語言程序設(shè)計實(shí)驗(yàn)指導(dǎo)與習(xí)題精解
- C#程序開發(fā)參考手冊