码迷,mamicode.com
首页 > 其他好文 > 详细

倒计时

时间:2016-09-22 21:10:33      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

public class CutDownLeftTime : MonoBehaviour
{
    public void InitLeftTime(int leftTimeSeconds, EventMainType eventType)
    {
        if (leftTimeSeconds > 0)
            StartCoroutine(CutDownTime(leftTimeSeconds, eventType));
    }

    float sceondUnit = 0;
    private IEnumerator CutDownTime(int leftTimeSeconds, EventMainType eventType)
    {
        while (true)
        {
            sceondUnit += Time.unscaledDeltaTime;
            if (sceondUnit >= 1)
            {
                leftTimeSeconds -= 1;
                GetComponent<UILabel>().text = new TimeSpan(0, 0, leftTimeSeconds).ToString();
                sceondUnit = 0;
                if (leftTimeSeconds <= 0)
                {
                    GameEvent evt = new GameEvent();
                    evt.EvtType = eventType;
                    TGameCore.GetIntance().GetEventMgr().SendEvent(evt);
                    yield break;
                }
            }
            yield return 0;
        }
    }

 

倒计时

标签:

原文地址:http://www.cnblogs.com/HelloUnity/p/5897819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!