using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
int hour;
int minute;
int second;
int millisecond;
// 已经花费的时间
float timeSpend = 0.0f;
// 显示时间区域的文本
Text text_timeSpend;
// Use this for initialization
void Start () {
text_timeSpend = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
timeSpend += Time.deltaTime;
GlobalSetting.timeSpent = timeSpend;
hour = (int)timeSpend / 3600;
minute = ((int)timeSpend - hour * 3600) / 60;
second = (int)timeSpend - hour * 3600 - minute * 60;
millisecond = (int)((timeSpend - (int)timeSpend) * 1000);
text_timeSpend.text = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
}
}
Unity3D中C#获取游戏时间并显示成秒表格式
最新推荐文章于 2023-12-13 19:47:17 发布