U3D中的协同等待函数

  WaitForSeconds.WaitForseconds等待函数;

  创建一个yield指令,来等待给定的秒数;

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class example:MonoBehaviour
 5 {
 6     public IEnumerator Awake()
 7 {
 8   print(Time.time);
 9   yield return new WaitForSeconds(5);
10   print(Time.time);        
11 }  
12 }
WaitForSeconds.WaitForSeconds

  注:

  1、必须添加接口IEnumerator,

  2、等待函数只能写在接口内;

知行合一
原文地址:https://www.cnblogs.com/YeYunRong/p/5058205.html