LoginSignup
1
1

More than 5 years have passed since last update.

unityでシンプルタイマーを表示する方法

Last updated at Posted at 2018-04-01

今回は、ゲームでもよく使う タイマーを表示する方法を見ていきます。 

 ステップ1   下準備



UIから Canvasを追加する。 

UIから Textを追加する。 

そして、TextをCanvasにドラッグします。 

Textの中は 00:00と 書いておきます。

大きさも微調整して、画面の右上に出るようにしておきます。

次に Add componetから NewScriptを追加します。 



bandicam 2018-04-01 10-38-38-543.jpg



 ステップ2 コードを書く



Scriptの中のコードは こんな感じ。 数字が増えていくだけの 

シンプルタイマーです。


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


public class time : MonoBehaviour {

    float countTime = 0;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        countTime += Time.deltaTime; 
        GetComponent<Text>().text = countTime.ToString("F2"); 

    }
}





結果

Game画面にタイマーが表示できる。

bandicam 2018-04-01 10-46-13-904.jpg




PS



UDEMYでUnityやC#講座などを出しています。 よかったら見てね~。 

私の名前で検索すれば 出てきますので。

1
1
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
1
1