刚开始学Unity的时候,最难搞定的就是这两个functions的差异,依照官方文件所描述的:
Awake():Awakeiscalledwhenthescriptinstanceisbeingloaded.
Start():StartiscalledjustbeforeanyoftheUpdatemethodsiscalledthefirsttime.
Awake()跟Start()差在哪?
习惯C++人来说,这根本是“小三”的颠倒!为什么要这样分搞不懂。后来写久了遇到问题了才了解原来继承MonoBehaviour的class:
Awake()==C++的Construct
Start()==程式启动后第一个会被忽叫的function
进一步想,我们在写C++的class时,不也有时候会自己写Init()的MemberFucntion吗?所以Start()也可想成自订的Init()就好!
虚幻UE4/unity/3d/maya场景模型特效人物游戏UI原画zb笔刷教程c4d淘宝¥18.8购买在使用上的基本原则就是,如果你有class的member参考其它Component,就在Awake里设定好,例如:
1
protectedvoidAwake(){
2
3
thisTrans=transform;
4
5
item=GetComponent();
6
7
}
这是确保当我们在Start()里需要呼叫member所参考