Unity中各种格式计时器

问题背景:

在开发游戏过程中,很多地方需要倒计时,但是各种地方要的倒计时格式不同,倒计时都会写,在这里不详细介绍,写的目的就是为了记录一下,方便复用(为了在开发过程中不为了小问题浪费不必要脑细胞)

1.格式:时分秒

 

3.格式(分秒)

public int timer = 190;
    //开启时间
    IEnumerator OpenTimer(int timer)
    {
        TimerText.text = string.Format("{0:D2}:{1:D2}", timer / 60, timer % 60);
        while (timer > 0)
        {
            yield return new WaitForSeconds(1);
            timer--;
            TimerText.text = string.Format("{0:D2}:{1:D2}", timer / 60, timer % 60);
        }
    }

 4.格式:天时分秒

 就这样,计时器这玩意没啥说的,仅为填充代码库,欢迎指正

原文地址:https://www.cnblogs.com/answer-yj/p/10684083.html