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

计时器

时间:2018-01-11 15:34:51      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:style   span   oat   wait   second   nbsp   pre   结束   summary   

    /// <summary>
    /// 计时器
    /// </summary>
    /// <param name="seconds"></param>
    /// <param name="timeout">时间结束的回调</param>
    /// <param name="timeUpdate">时间更新的回调</param>
    /// <returns></returns>
    public static IEnumerator Timer(float seconds, Action timeout, Action<float> timeUpdate)
    {
        float time = seconds;
        while (true)
        {
            if (time < 0)
            {
                timeout();
                yield break;
            }
            else
            {
                timeUpdate(time);
            }
            time -= Time.deltaTime;
            yield return new WaitForFixedUpdate();
        }
    }

 

计时器

标签:style   span   oat   wait   second   nbsp   pre   结束   summary   

原文地址:https://www.cnblogs.com/0315cz/p/8267274.html

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