タイムアタックを作ろう/UIテキストの使い方









タイムアタック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using TMPro;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour
{
public TextMeshProUGUI timeLabel;
public int timeCount;
void Start()
{
timeLabel.text = "TIME:" + timeCount;
StartCoroutine(Timer());
}
// (テクニック)コルーチン
private IEnumerator Timer()
{
// (ポイント)処理を繰り返す
while (true)
{
// (ポイント)処理を一定時間だけ中断させる
yield return new WaitForSeconds(1);
timeCount -= 1;
timeLabel.text = "TIME:" + timeCount;
if (timeCount < 1)
{
SceneManager.LoadScene("GameOver");
}
}
}
}


【2022版】BallGame(全27回)
他のコースを見る








タイムアタック
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using TMPro;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour
{
public TextMeshProUGUI timeLabel;
public int timeCount;
void Start()
{
timeLabel.text = "TIME:" + timeCount;
StartCoroutine(Timer());
}
// (テクニック)コルーチン
private IEnumerator Timer()
{
// (ポイント)処理を繰り返す
while (true)
{
// (ポイント)処理を一定時間だけ中断させる
yield return new WaitForSeconds(1);
timeCount -= 1;
timeLabel.text = "TIME:" + timeCount;
if (timeCount < 1)
{
SceneManager.LoadScene("GameOver");
}
}
}
}


タイムアタックを作ろう/UIテキストの使い方