您的位置:首页 > 移动开发 > Unity3D

unity3D脚本的生命周期

2017-06-13 20:59 253 查看
组件绑定脚本请看:http://blog.csdn.net/tutuboke/article/details/40894433

绑定后。先写脚本,代码例如以下:

using UnityEngine;
using System.Collections;

public class Test1 : MonoBehaviour {
//变量设置为public 能够再unity3D的编辑器中调节 初值及运行时可能查到值得时时变化
public int i;
public int j;
public int k;
//唤醒一个脚本 第一个运行 运行一次
void Awake(){
Debug.Log ("Awake");
}
// 開始  运行一次
void Start () {
Debug.Log("Start");
}
//绘制界面的  每帧都会调用
void OnGUI()
{
if (k==0)
Debug.Log ("onGui");
k = 1;
}
// 每帧都运行update
void Update () {
if (i == 0)
{
Debug.Log("Update");
}
}
//update函数之后调用 每帧都会调用
void LateUpdate(){
if (i == 0)
{
Debug.Log("LateUpdate");
i = 1;
}
}
//定时调用
//Edit->preject setting ->Time -> (Inspector监測视图)Fixed Timestep 设置刷新时间
void FixedUpdate(){
if (j==0)
Debug.Log("FixedUpdate");
j = 1;
}
//绑定的组件被删除调用
void OnDestroy()
{
Debug.Log("OnDestroy");
}
}


执行u3d ui编辑器,在UI编辑器的左下角查看执行信息及log 出现效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: