Unity 使用协程实现倒计时功能

using  UnityEngine;
using  System.Collections;
  
public  class  ShowNumber : MonoBehaviour {
     private  int  tmp = 10;
 
     void  Start () {
         //开启一个协程
         StartCoroutine( "changeTime" );
     }
      
     IEnumerator changeTime()
     {
         while (tmp > 0)
         {
             //暂停一秒
             yield  return  new  WaitForSeconds(1);
             tmp--;
         }
     }
}

你可能感兴趣的:(Unity)