使用startCoroutine制定倒计时

使用startCoroutine制定倒计时

using UnityEngine;
using System.Collections;

public class TimerCoroutine : MonoBehaviour
{
    public int second;
 // Use this for initialization
 void Start ()
 {
        StartCoroutine("timeSecond");
 }

    void OnGUI()
    {
        GUI.Label(new Rect(100, 100, 100, 100), second.ToString());
    }

    IEnumerator timeSecond()
    {
        while(second>0)
        {
            yield return new WaitForSeconds(1f);
            second -= 1;

            Debug.Log("second" + second);
        }
    }
 
}

  

posted @ 2015-10-22 14:44  will.Deng  阅读(407)  评论(0编辑  收藏  举报