C#做一个秒表
1、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Time0 : MonoBehaviour {
private int hour;
private int minute;
private int second;
private int millisecond;
public float timeSpend = 0.0f;
public int MyTime;
public Text text;
private void Update()
{
timeSpend += Time.deltaTime;
hour = (int)timeSpend / 3600;
minute = ((int)timeSpend - hour * 3600) / 60;
second = (int)timeSpend - hour * 3600 - minute * 60;
millisecond = (int)((timeSpend - (int)timeSpend) * 1000);
text.text = string.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
}
2表现效果
|
请发表评论