Awake & Start
【Awake & Start】
MonoBehaviour.Awake()
Awake is used to initialize any variables or game state before the game starts. Awake is called only once during the lifetime of the script instance. Awake is called after all objects are initialized so you can safely speak to other objects or query them using eg. GameObject.FindWithTag. Each GameObject's Awake is called in a random order between objects. Because of this, you should use Awake to set up references between scripts, and use Start to pass any information back and forth. Awake is always called before any Start functions. This allows you to order initialization of scripts. Awake can not act as a coroutine.
Awake is called when the script object is initialised, regardless of whether or not the script is enabled.
可以将Awake当作构造函数来使用。
using UnityEngine;
using System.Collections; public class Example : MonoBehaviour {
private GameObject target;
void Awake() {
target = GameObject.FindWithTag("Player");
}
}
MonoBehaviour.Start()
Start在enable为true的时候,在第一次调update前会被调。
Where objects are instantiated during gameplay, their Awake function will naturally be called after the Start functions of scene objects have already completed.

当我们为MonoBehavior定义了[ExecuteInEditMode]后,我们还需要关心Awake和Start在编辑器中的执行状况。
当该MonoBehavior在编辑器中被赋于给GameObject的时候,Awake, Start 将被执行。
当Play按钮被按下游戏开始以后,Awake, Start 将被执行。
当Play按钮停止后,Awake, Start将再次被执行。
当在编辑器中打开包含有该MonoBehavior的场景的时候,Awake, Start将被执行。
参考:
1、file:///D:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/Documentation/ScriptReference/MonoBehaviour.Awake.html
2、file:///D:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/Documentation/ScriptReference/MonoBehaviour.Start.html
3、http://www.cnblogs.com/xpvincent/p/3178042.html
Awake & Start的更多相关文章
- Unity学习疑问记录之Awake和Update
Awake() 当一个脚本实例被载入时Awake被调用. Awake用于在游戏开始之前初始化变量或游戏状态.在脚本整个生命周期内它仅被调用一次.Awake在所有对象被初始化之后调用,所以你可以安全的与 ...
- Best Practices for Background Jobs_3 Managing Device Awake State之电源锁、Alarm、WakefulBroadcastReceiver
http://developer.android.com/training/scheduling/index.html 当静置一个设备的时候,先会屏幕变暗,然后关闭屏幕,最后关闭CPU,以省电.但有的 ...
- Unity and C#: Game Loop (Awake, Start, Update)
Introduction The central component of any game, from a programming standpoint, is the game loop. It ...
- unity awake start 的区别
void Awake (){ } //初始化函数,在游戏开始时系统自动调用.一般用来创建变量之类的东西. void Start(){ } //初始化函数,在所有Awake函数运行完之后(一般是这样,但 ...
- Tip8:Unity中诸如 Awake() Start() Update()等函数的 执行顺序
Unity脚本中有很多的事件函数,下面是各种函数的执行顺序: 1.reset(); 2.Awake(); 3.OnEnable; 4.OnLevelWasLoaded(); 5.Start(); 6. ...
- [Unity3D]脚本中Start()和Awake()的区别
Unity3D初学者经常把Awake和Start混淆. 简单说明一下,Awake在MonoBehavior创建后就立刻调用,Start将在MonoBehavior创建后在该帧Update之前,在该Mo ...
- Awake和Start
经过查阅资料和自己的理解整理出来的,欢迎大家指教. Awake和Start对比 awake比start先执行. 当有多个类的时候,所有类的awake执行完了才会执行start. awake里面一般放初 ...
- Unity3d Awake、OnEnable、Start生命周期
Unity3d,Awake.OnEnable.Start,都是游戏开始运行前,所运行的方法. GameObject的Activity为true,脚本的enable为true时,其先后顺序为:Awake ...
- Unity3d中的Awake()、OnEnable()、Start()等默认函数的执行顺序和生命周期
Awake()在MonoBehavior创建后就立刻调用,在脚本实例的整个生命周期中,Awake函数仅执行一次:如果游戏对象(即gameObject)的初始状态为关闭状态,那么运行程序,Awake函数 ...
- [Unity3D]脚本中Start()和Awake()的差别
Unity3D刚開始学习的人常常把Awake和Start混淆. 简单说明一下,Awake在MonoBehavior创建后就立马调用,Start将在MonoBehavior创建后在该帧Update之前. ...
随机推荐
- DRF 的视图,路由和渲染器
DRF 的视图,路由和渲染器 1 视图 简单的增删改查 : ModelViewSet; 复杂的操作使用APIView 和 GenericViewSet APIView(View) class Home ...
- Beego的controller怎么用嵌入实现继承问题
Go Lang是无继承层次的轻量级面向对象编程范式.Go Lang中的接口与实现之间完全是非侵入式的.这种接口实现方式很值得称赞.不但如此,在Go Lang中只有类型嵌入而没有类型继承.这规避了很多与 ...
- linux下 /boot 分区空间不足及其衍生问题
linux的/boot引导分区有时会提示空间不足的问题,虽不影响系统的正常运行,但是人类天生对于未知的恐惧感总是影响心情的.而且在按安装其他软件的过程在中可能会出现以下问题: gzip: stdout ...
- SGU 502 Digits Permutation
这个题目 正解应该是 dp 吧 对18个数字进行2进制枚举放不放,,,可以这么理解 以当前状态 stu,他对应的余数是 h 进入下一个状态: 进行记忆画搜索就行了 1 #include<iost ...
- 21天学通C++_Day1
被阿里实习生的第一轮电话面试刷掉以后,幡然醒悟,发现以前学习的C++基础一点都不扎实.为了把基础打扎实,重新学习一遍:为了让自己不放弃,也顺便可以把当天学到的东西记录下来,开始了写博客. 学习书籍:& ...
- VC++ windows开机自启动设置
设置开机启动 很多软件要求软件能够在开机时自启动,下面讲讲如何设置开机自启动. Windows设置程序的开机启动的方法有很多,这里只讲其中的一种,该方法同时适用于32位和64位的操作系统,只需将需要开 ...
- LeetCode Optimal Division
原题链接在这里:https://leetcode.com/problems/optimal-division/description/ 题目: Given a list of positive int ...
- CF311B Cats Transport
题意 Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straigh ...
- 十一、python沉淀之路--map函数、filter函数、reduce函数、匿名函数、内置函数
一.map函数 1.自定义函数,实现类似于map函数的功能 num_l = [1,3,4,5,6,9] def power(n): return n ** 2 def map_test(func,ar ...
- yii2 csrf验证原理分析
知识补充 因为yii2 csrf的验证的加解密 涉及到异或运算 所以需要先补充php里字符串异或运算的相关知识,不需要的可以跳过 ^异或运算不一样返回1 否者返回 0在PHP语言中,经常用来做加密的运 ...