倒计时

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;
        }
    }

 

posted @ 2016-09-22 20:27  贴心小冰棍  阅读(210)  评论(1编辑  收藏  举报