Created
September 6, 2019 06:02
-
-
Save mrgarita/01394cb54e849bdbc4f438cca27b56cb to your computer and use it in GitHub Desktop.
Unity:カウントダウンタイマー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class CountDown : MonoBehaviour { | |
public static float CountDownTime; // カウントダウンタイム | |
public Text TextCountDown; // 表示用テキストUI | |
// Use this for initialization | |
void Start () { | |
CountDownTime = 60.0F; // カウントダウン開始秒数をセット | |
} | |
// Update is called once per frame | |
void Update () { | |
// カウントダウンタイムを整形して表示 | |
TextCountDown.text = String.Format("Time: {0:00.00}", CountDownTime); | |
// 経過時刻を引いていく | |
CountDownTime -= Time.deltaTime; | |
// 0.0秒以下になったらカウントダウンタイムを0.0で固定(止まったように見せる) | |
if (CountDownTime <= 0.0F) | |
{ | |
CountDownTime = 0.0F; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment