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

  • 相关阅读:
    利用python 学习数据分析 (学习四)
    numpy 模块常用方法
    利用python 学习数据分析 (学习三)
    numpy 常用方法2
    瞎JB逆
    Codeforces 907 矩阵编号不相邻构造 团操作状压DFS
    AT Regular 086
    矩阵快速幂 求斐波那契第N项
    指数循环节(指数降幂)
    Educational Codeforces Round 32
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3804290.html
Copyright © 2011-2022 走看看