實現倒計時功能

新建文本,實現倒計時功能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");
    }
}
相關文章
相關標籤/搜索