/// <summary>
/// 倒计时文本
/// </summary>
private Text RedRainTimerText;
int hour;
int minute;
int second;
int millisecond;
// 1小时 时 分 秒
float timeSpend = 4*60*60;
private void FixedUpdate()
{
// 倒计时刷新
if (RedRainTimerText.gameObject.activeInHierarchy)
{
// 累加计时 timeSpend += Time.deltaTime;
// 倒计时
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);
RedRainTimerText.text = string.Format ("{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
}
}
unity累加计时和倒计时实现
最新推荐文章于 2024-09-10 10:27:33 发布