您当前的位置: 首页 >  unity

云小川

暂无认证

  • 4浏览

    0关注

    78博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity 计时器

云小川 发布时间:2022-03-30 16:56:07 ,浏览量:4

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

public class JiShi : MonoBehaviour
{
    private float timer = 0f;
    private int h = 10;
    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; }
        Debug.Log(string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s));
    }
    void OnGUI()
    {
        timeStr = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
        GUI.Label(new Rect(10, 10, 100, 200), timeStr);
    }
}

关注
打赏
1663746399
查看更多评论
立即登录/注册

微信扫码登录

0.0353s