计时器编辑

计时器编辑,第1张

计时器编辑
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimerText : MonoBehaviour
{
    ///Way 2
    int hour;
    int minute;
    int second;
    int millisecond;
    bool shouldCount = false;

    public float timeSpent = 0.0f;



    void onEnable()
    {
        shouldCount = true;
    }

    void Update()
    {
        if (shouldCount)
        {
            timeSpent += Time.deltaTime;

            //hour = (int)timeSpent / 3600;
           // minute = ((int)timeSpent - (int)timeSpent / 3600 * 3600) / 60;
            second = (int)timeSpent - (int)timeSpent / 3600 * 3600 - ((int)timeSpent - (int)timeSpent / 3600 * 3600) / 60 * 60;
            millisecond = (int)((timeSpent - (int)timeSpent) * 1000);

            //text_timeSpent.text = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
            GetComponent().text = string.Format("{0:D2}.{1:D3}",  second, millisecond);
        }
    }

    //void onDestroy
    void onDisable()
    {
        shouldCount = false;
        GetComponent().text = "";
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5658397.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存