LoginSignup
2
3

More than 5 years have passed since last update.

Unity ~手抜きカウントダウンの作り方!!~

Posted at

コード

新しくこんなん作ります

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


public class CountDown : MonoBehaviour {

    public float MAX_TIME = 5;
    float timeCount ;

    // Use this for initialization
    void Start () {
        timeCount = MAX_TIME;
        GetComponent<Text>().text = ((int)timeCount).ToString();

    }

    // Update is called once per frame
    void Update () {
        timeCount -= Time.deltaTime;
        GetComponent<Text>().text = ((int)timeCount).ToString();
        if (timeCount <= 1)
        {
            GetComponent<Text>().text = "スタート!!";
        }
    }
}

using UnityEngine.UIを追加忘れずに

Time.deltaTimeこれ書くとまぁ色々unityがうまくしてくれてマシンスペックに関係なく1秒を1秒と数えてくれます

適当なTextオブジェクトにスクリプトをadd

MAX_TIMEをパブリックにしてるからUI上で変更出来ます!

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3