实现倒计时功能

新建文本,实现倒计时功能spa

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour {

    public Text timeText;
    private float gameTime = 60;
    private bool gameOver;
    
    // Update is called once per frame
    void Update () {
        if (gameOver)
        {
            return;
        }
        gameTime -= Time.deltaTime;
        if (gameTime<=0)
        {
            gameTime = 0;
            //
            gameOver = true;
            return;
        }
      
        timeText.text = gameTime.ToString("0");
    }
}
相关文章
相关标签/搜索