using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class test : MonoBehaviour
{
private float nowTime;
public Text timeText;
public bool isStart=false;
void Update()
{
if (isStart)
{
nowTime += Time.deltaTime;
int hour = (int)nowTime / 3600;
int minute = (int)(nowTime - hour * 3600) / 60;
int second = (int)(nowTime - hour * 3600 - minute * 60);
timeText.text = string.Format("{0:D2}:{1:D2}", minute, second);
}
}
//開始計時
public void startJiShi()
{
nowTime = 0;
isStart = true;
}
//停止計時
public void tingZhiJiShi()
{
isStart = false;
}
}
做出的效果如下: