下面是有关Unity脚本的生命周期的代码,有兴趣的同学可以看一下,具体的就不多说了,主要是分享一下这个源码,供大家在以后的工作中能用的上。
绑定后,先写脚本,代码如下:
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 出现效果:

Unity脚本的生命周期