YouTube でタイマーを作成する方法に関するチュートリアルに従ってきましたがGUIText
、Unity 5 の問題のために行き詰まりました。これが私のコードです。
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Timer : MonoBehaviour {
public float Seconds = 59;
public float Minutes = 0;
void Update() {
if (Seconds <= 0) {
Seconds = 59;
if (Minutes > 1) {
Minutes--;
} else {
Minutes = 0;
Seconds = 0;
//This makes the guiText show the time as X:XX. ToString.("f0") formats it so there is no decimal place.
GameObject.Find("TimerText").GUIText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");
}
} else {
Seconds -= Time.deltaTime;
}
//These lines will make sure that the time is shown as X:XX and not X:XX.XXXXXX
if(Mathf.Round(Seconds) <= 9) {
GameObject.Find("TimerText").GUIText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");
} else {
GameObject.Find("TimerText").GUIText.text = Minutes.ToString("f0") + ":" + Seconds.ToString("f0");
}
}
}
問題は、GUIText
.
エラー CS1061: タイプ 'UnityEngine.GameObject' に 'GUIText' の定義が含まれておらず、タイプ 'UnityEngine.GameObject' の拡張メソッド 'GUIText' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?)
なしでゲームにタイマーを表示するにはどうすればよいGUIText
ですか?