42 lines
783 B
C#
42 lines
783 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class RunTimeUpdate : MonoBehaviour
|
|
{
|
|
public TextMeshPro text;
|
|
private void OnEnable()
|
|
{
|
|
StartCoroutine(RunTimeStart());
|
|
}
|
|
|
|
int minutes;
|
|
int hours;
|
|
string nowTime;
|
|
IEnumerator RunTimeStart()
|
|
{
|
|
|
|
while (true)
|
|
{
|
|
// 等待60秒
|
|
yield return new WaitForSeconds(60f);
|
|
|
|
// 增加1分钟
|
|
minutes++;
|
|
|
|
// 检查进位
|
|
if (minutes >= 60)
|
|
{
|
|
hours++;
|
|
minutes = 0;
|
|
|
|
}
|
|
|
|
// 格式化为 HH:mm
|
|
string timeString = $"{hours:D2}:{minutes:D2}";
|
|
text.text = timeString;
|
|
}
|
|
}
|
|
}
|