美文网首页
计时器格式为:00:00:00Day0815

计时器格式为:00:00:00Day0815

作者: 段然丶 | 来源:发表于2017-08-15 17:29 被阅读0次

    using UnityEngine;

    using System.Collections;

    public class   Test01  : 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 >= 24)

                        {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);

    }

    }

    相关文章

      网友评论

          本文标题:计时器格式为:00:00:00Day0815

          本文链接:https://www.haomeiwen.com/subject/duimrxtx.html