【Unity】Time.timeを使ってみる
Unityでゲーム開始からの経過時間によって処理を変えるということをやりたかったので、Time.timeを使って実装することにした。
実装の前に、Time.timeがどんなものか実験してみようと思う。
今回は画面に表示されたテキストにゲームを起動からの経過時間を表示する。
テキストオブジェクトを追加して以下のスクリプトをアタッチした。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TimeTest : MonoBehaviour
{
private Text timeText = null;
// Start is called before the first frame update
void Start()
{
timeText = gameObject.GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
timeText.text = Convert.ToString(Time.time);
}
}ゲーム開始時間からの秒数を表示させることができた。
