Unity 学习笔记 - 简单实现 用时分秒显示时间

代码

private float nowTime;
public Text timeText;

void Update()
    {
        nowTime += Time.deltaTime;
        int hour = (int)nowTime / 3600;
        int minute = (int)(nowTime - hour * 3600) / 60;
        int second = (int)(nowTime - hour * 3600 - minute * 60);
        int millSecond = (int)((nowTime - (int)nowTime) * 1000);
        
        timeText.text = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}", hour, minute, second, millSecond);
    }

效果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/EdmundRF/article/details/89518959