新建文本,实现倒计时功能
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"); } }
原文:https://www.cnblogs.com/dream-seeker-201907/p/11605998.html