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之前. ...
随机推荐
- NLTK下载语言素材中碰到的certificate verify failed (_ssl.c:749)
NLTK是什么? NLTK是一个开源的项目,包含:Python模块,数据集和教程,用于NLP的研究和开发. NLTK由Steven Bird和Edward Loper在宾夕法尼亚大学计算机和信息科学系 ...
- hihocoder-1483区间价值 (二分+尺取法)
题目链接: 区间价值 给定n个数A1...An,小Ho想了解AL..AR中有多少对元素值相同.小Ho把这个数目定义为区间[L,R]的价值,用v[L,R]表示. 例如1 1 1 2 2这五个数所组成的区 ...
- 从无到有开发自己的Wordpress博客主题---局部模板的准备
毫无疑问,我们媒体页面都会有header和footer,这些用到的内容几乎是一样的. 从无到有,我们先不考虑后面可能用到的Search和Comment等的模板,后面的我会在文本最后面追加. 开始之前, ...
- golang:bson.ObjectId与string转化
网上资料不好搜,记下来:两个变量:id bson.ObjectIdstr string bson.ObjectId—>string id.Hex() string—>bson.Object ...
- ORM 模型层
一个模型就是一个单独的,确定的数据的信息源,包含了数据的字段和操作方法.通常,每个模型映射为一张数据库中的表 基本原则: 每个模型在Django中的存在形式为一个python类 每个模型都是djang ...
- cocos2d-x android8.0 视频层遮挡问题
cocos里默认情况下视频层是在cocos 层的上面,如果希望把视频层放在cocos的下面的话, android8.0以下,把Cocos2dxVideoHelper.java里的 videoView. ...
- 老师木发的makefile与autotools
makefile http://scc.qibebt.cas.cn/docs/linux/base/%B8%FA%CE%D2%D2%BB%C6%F0%D0%B4Makefile-%B3%C2%F0%A ...
- C++中cin的使用总结
在学习C++时大家肯定迷惑过关于输入输出各种输出函数的功能,现在来总结一下各种函数的简单用法. cin建有一个缓冲区,即输入缓冲区.一次输入过程是这样的,当一次键盘输入结束时会将输入的数据存入输入缓冲 ...
- Qt5.4中遇到找不到头文件<QApplication>等。
从新学习Qt时,重装了Qt5.4,当运行Hello World例子时,遇到了下列的情况 <span style="font-size:18px;">#include & ...
- Verilog中的UDP
概述 Verilog HDL语言提供了一种扩展基元的方法,允许用户自己定义元件(User Defined Primitives,UDP).通过UDP,可以把一块组合逻辑电路或者时序逻辑电路封装在一个U ...