zoukankan      html  css  js  c++  java
  • 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当作构造函数来使用。

    1 using UnityEngine;
    2 using System.Collections;
    3 
    4 public class Example : MonoBehaviour {
    5     private GameObject target;
    6     void Awake() {
    7         target = GameObject.FindWithTag("Player");
    8     }
    9 }
    View Code

    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

  • 相关阅读:
    0.0pomelo的优缺点
    python操作MySQL
    MySQL-基本查询语句及方法,连表和子查询
    MySQL-外键对应关系
    MySQL--存储引擎、数据类型、约束条件
    数据库MySQL安装、基本指令
    并发编程-协程、池,io模型
    python并发编程-GIL全局解释锁,Event事件,信号量
    并发编程-线程
    并发编程-进程
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3804290.html
Copyright © 2011-2022 走看看