using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class timer: MonoBehaviour
{
public float timer = 3;//倒計時幾秒
public GameObject t;//畫布下的文本框
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (timer > 0)
{
timer -= Time.deltaTime;
t.GetComponent<Text>().text = timer.ToString("00");//這個意思是取整數的意思,如果想取小數那麼就要ToString("0.0")
}
else GameOver();
}
void GameOver()
{
t.GetComponent<Text>().text = "Gameover";
}
}
倒計時
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.