方法一:
using System.Collections;
using System.Collections.Generic;
using Unity.UIWidgets.widgets;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
public class CoutdownTmer : MonoBehaviour
{
private UnityEngine.UI.Text txtimer;
public int second = 120;
private void Start()
{
txtimer = this.GetComponent<UnityEngine.UI.Text>();
}
private float nextime=1; //下次修改的时间
private void Update()
{ //如果到了修改时间 (用来修改原来的每帧改变,换成每秒改变)
if (Time.time>=nextime)
{
second--;
txtimer.text = string.Format("{0:d2}:{1:d2}", second / 60, second % 60);
nextime = Time.time + 1;
if (second <= 10)
{
txtimer.color = Color.red;
}
}
}
}
f
方法二: