Unity-時間轉換顯示

原文鏈接:https://blog.csdn.net/WHYunique/article/details/91604259

把該腳本直接託給要顯示的文本上即可
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GetTime : MonoBehaviour
{

private int hour;
private int minute;
private int second;
private int millisecond;

//已經花費的時間
float timeSpeed = 0.0f;

//顯示時間區域的文本
Text text_timeSpeed;

// Use this for initialization
void Start ()
{
text_timeSpeed = GetComponent();
}

// Update is called once per frame
void Update ()
{
timeSpeed += Time.deltaTime;
hour = (int)timeSpeed / 3600;
minute = ((int)timeSpeed - hour * 3600) / 60;
second = (int)timeSpeed - hour * 3600 - minute * 60;
//text_timeSpeed.text = string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, second);
millisecond = (int)((timeSpeed - (int)timeSpeed) * 1000);
text_timeSpeed.text = string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D3}", hour, minute, second, millisecond);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章