当前位置:网站首页>Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00

Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00

2022-07-06 20:13:00 LiPing122335

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class jishi : MonoBehaviour {

    private float timer = 0f;
    private int h = 0;
    private int m = 0;
    private int s = 0;
    private string timeStr = string.Empty;
    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= 1f) { s++; timer = 0; }
        if (s >= 60) { m++; s = 0; }
        if (m >= 60) { h++; m = 0; }
        if (h >= 99) { h = 0; }
    }
    void OnGUI()
    {
        timeStr = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
        GUI.Label(new Rect(10, 10, 100, 200), timeStr);
    }
}
 

原网站

版权声明
本文为[LiPing122335]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131232205932.html