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之前. ...
随机推荐
- git pull VS git fetch&merge
使用git fetch和git pull都可以更新远程仓库的代码到本地,但是它们之间还是有区别. git fetch git fetch origin master git log -p maste ...
- PHP防止mysql注入方法
本文纲要: 1. 初始化你的变量 2. 一定记得要过滤你的变量 [一.在服务器端配置] 安全,PHP代码编写是一方面,PHP的配置更是非常关键. 我们php手手工安装的,php的默认配置文件在 /us ...
- 旧书重温:0day2【5】shellcode变形记
紧接上一篇,结合第一篇 //这篇文章主要成功溢出一个带有缓冲区溢出的小程序,其中我们的shellcode被strcpy截断了所以我们需要变形shellcode,这个实验中也出现了很多意想不到的拦路虎, ...
- vs中删除nuget包
最近发现有些解决方案都是用来nuget包,这个偶尔能跑,但是有一个爱抽风的毛病,生成解决方案的时候报错:无法连接到远程服务器,真几把蛋疼.... 就是下图的情况 网上找了下不是很容易找到处理这个问题的 ...
- Python sh库学习
官方文档有句话"allows you to call any program",并且: helps you write shell scripts in Python by giv ...
- hadoop文件IO
InputStreamReader 是字节流通向字符流的桥梁:它使用指定的 charset 读取字节并将其解码为字符.它使用的字符集可以由名称指定或显式给定,或者可以接受平台默认的字符集. Input ...
- C#获取文件的MD5码
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Send ...
- 调用 SSPI 失败,请参见内部异常 解决方法
2017-11-12 12:49:53:706] OnServerConnectionAvailable error : System.Security.Authentication.Authenti ...
- PDF通过剪裁来实现打印字体变大
之前打印论文,很多都是一页两版,这个时候字体会非常小:打印缩放放大后,字又容易出了打印边界. 这种情况可以采用Adobe IX Pro(只要是pro应该都可以)进行边缘裁剪来实现字体放大.只需要剪裁( ...
- Java课程设计——坦克大战
坦克大战——坦克类 一. 团队课程设计博客链接 https://www.cnblogs.com/chenhuilin/p/10275664.html 二.个人负责模块和任务说明 模块:坦克类(玩家坦克 ...