返回介绍

MonoBehaviour.Start() 开始

发布于 2019-12-18 15:38:04 字数 1825 浏览 1244 评论 0 收藏 0

Description 描述

Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.

Start仅在当第一次脚本启用Update方法被调用之前调用。

Like the Awake function, Start is called exactly once in the lifetime of the script. However, Awake is called when the script object is initialised, regardless of whether or not the script is enabled. Start may not be called on the same frame as Awake if the script is not enabled at initialisation time.

就像Awake函数,在该脚本的生命周期Start被初始化一次。然而,Awake被调用时在脚本对象初始化时调用,不管脚本是否被启用。在同一帧如果在初始化的时候没有启用脚本,Start不会被调用。

The Awake function is called on all objects in the scene before any object's Start function is called. This fact is useful in cases where object A's initialisation code needs to rely on object B's already being initialised; B's initialisation should be done in Awake while A's should be done in Start.

在任何对象Start函数被调用之前,Awake函数在场景所有对象被调用。这其实是很有用的,对象A的初始化代码依赖对象B已经被初始化,对象B初始化应该在Awake中,A的代码应该在Start中。

Where objects are instantiated during gameplay, their Awake function will naturally be called after the Start functions of scene objects have already completed.

凡对象在游戏时实例化,在场景对象的Start的函数已经完成之后,它们的Awake函数自然被调用。

JavaScript:

// Initializes the target variable.
// target is private and thus not editable in the inspector
 
private var target : GameObject;
 
function Start () { 
	target = GameObject.FindWithTag ("Player"); 
} 

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    private GameObject target;
    void Start() {
        target = GameObject.FindWithTag("Player");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文