首页 > 其他 > 详细

倒计时

时间:2016-09-22 21:08:47      阅读:154      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!