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

  • 相关阅读:
    Ubuntu 19.04安装phpipam软件
    ubuntu snmp 安装与配置
    xcode 拷贝新的ios image 进去以后 出现 the divices is locked
    常用 Git 命令清单
    ios 从工程中删除Cocoapods
    ios app上架流程
    MySql某一列累计查询
    Docx4j将html转成word时,br标签为软回车的问题修改
    java面试题
    java获取classpath
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3804290.html
Copyright © 2011-2022 走看看