Skip to content

Instantly share code, notes, and snippets.

@mrgarita
Created September 6, 2019 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarita/01394cb54e849bdbc4f438cca27b56cb to your computer and use it in GitHub Desktop.
Save mrgarita/01394cb54e849bdbc4f438cca27b56cb to your computer and use it in GitHub Desktop.
Unity:カウントダウンタイマー
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