unity3d 延迟执行脚本语句 在Unity3D中,有yield语句它负责延迟操作,yield return WaitForSeconds(3.0); //等待 3 秒
查看unity3d脚本手册,用法需要在相应的格式。
下面代码含义就是,加载图片显示等待6秒后进入场景level1中。
using UnityEngine;
using System.Collections;
public class init : MonoBehaviour {
// Use this for initialization
public Texture img;
private bool bl = false;
public float waitTime ;
void Start () {
StartCoroutine( wait(6.0f) );
}
// Update is called once per frame
void Update () {
if (bl)
Application.LoadLevel(1);
}
void OnGUI()
{
GUI.DrawTexture(new Rect(0,0,1024,768),img);
}
IEnumerator wait(float time)
{
yield return new WaitForSeconds(waitTime);
bl = true;
}
}