assignment
public Text timeText; //在unity里的定义
Assign the text by dragging and dropping in unity
or by GmeOject.Find
(find the gameObject named timeUI in the Hierarchy, and then get the above text component)
timeText=GameObject.Find("timeUI").GetComponent<Text>();
text control
private float timenum=60;
void Update()
{
timenum -= Time.deltaTime;
if(timenum<=0)
{
timenum = 0;
return;
}
//timeText上的文本显示为timenum的大小,并且以整数形式显示
timeText.text = timenum.ToString("0");
}
illustrate
- Time.deltaTime incremental time, you can refer to the following blog to understand
the understanding of incremental time - timeText.text = timenum.ToString("0"); "0" means in integer form, "0.0" means a decimal form