タイムアタックを作ろう/UIテキストの使い方
![8f1e2a05 ab06 4c98 9891 098fba71587d](https://codegenius.org/uploads/slide/image/512/8f1e2a05-ab06-4c98-9891-098fba71587d.jpeg)
![0ef4fdc7 2e6f 41eb a15a beae76478237](https://codegenius.org/uploads/slide/image/513/0ef4fdc7-2e6f-41eb-a15a-beae76478237.jpeg)
![Cbee0fc3 1ef6 47f6 bdfe 23afe93e673c](https://codegenius.org/uploads/slide/image/514/cbee0fc3-1ef6-47f6-bdfe-23afe93e673c.jpeg)
![5c485003 5000 45b2 87da a73d0aef5f03](https://codegenius.org/uploads/slide/image/515/5c485003-5000-45b2-87da-a73d0aef5f03.jpeg)
![B6290a15 5f30 4dcd 914d 4b970db9110d](https://codegenius.org/uploads/slide/image/516/b6290a15-5f30-4dcd-914d-4b970db9110d.jpeg)
![B1d57257 95ad 40e3 a00d b9b5fd3ba3f3](https://codegenius.org/uploads/slide/image/517/b1d57257-95ad-40e3-a00d-b9b5fd3ba3f3.jpeg)
![12e20570 461d 4134 8732 2deb12ece06a](https://codegenius.org/uploads/slide/image/518/12e20570-461d-4134-8732-2deb12ece06a.jpeg)
タイムアタックを作る
using UnityEngine;
using System.Collections;
// ★追加
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour {
// ★追加
public Text timeLabel;
public float timeCount;
// ★追加
void Start () {
timeLabel.text = "TIME;" + timeCount;
}
// ★追加
void Update () {
timeCount -= Time.deltaTime;
// ToString("0")は小数点を切り捨て
// 小数点1位まで表示するにはToString("n1")
// 小数点2位まで表示するにはToString("n2")
timeLabel.text = "TIME;" + timeCount.ToString("0");
if(timeCount < 0){
SceneManager.LoadScene("GameOver");
}
}
}
![D37435b4 a2b7 4f03 9c9c 658d7da0bafe](https://codegenius.org/uploads/slide/image/519/d37435b4-a2b7-4f03-9c9c-658d7da0bafe.jpeg)
![Be157c4c b9bf 44d9 b4a0 6a9480d50f79](https://codegenius.org/uploads/slide/image/520/be157c4c-b9bf-44d9-b4a0-6a9480d50f79.jpeg)
![B396fb37 4439 486a 829b 6424507aaf0e](https://codegenius.org/uploads/slide/image/521/b396fb37-4439-486a-829b-6424507aaf0e.jpeg)
【旧版】BallGame(全25回)
他のコースを見る![8f1e2a05 ab06 4c98 9891 098fba71587d](https://codegenius.org/uploads/slide/image/512/8f1e2a05-ab06-4c98-9891-098fba71587d.jpeg)
![0ef4fdc7 2e6f 41eb a15a beae76478237](https://codegenius.org/uploads/slide/image/513/0ef4fdc7-2e6f-41eb-a15a-beae76478237.jpeg)
![Cbee0fc3 1ef6 47f6 bdfe 23afe93e673c](https://codegenius.org/uploads/slide/image/514/cbee0fc3-1ef6-47f6-bdfe-23afe93e673c.jpeg)
![5c485003 5000 45b2 87da a73d0aef5f03](https://codegenius.org/uploads/slide/image/515/5c485003-5000-45b2-87da-a73d0aef5f03.jpeg)
![B6290a15 5f30 4dcd 914d 4b970db9110d](https://codegenius.org/uploads/slide/image/516/b6290a15-5f30-4dcd-914d-4b970db9110d.jpeg)
![B1d57257 95ad 40e3 a00d b9b5fd3ba3f3](https://codegenius.org/uploads/slide/image/517/b1d57257-95ad-40e3-a00d-b9b5fd3ba3f3.jpeg)
![12e20570 461d 4134 8732 2deb12ece06a](https://codegenius.org/uploads/slide/image/518/12e20570-461d-4134-8732-2deb12ece06a.jpeg)
タイムアタックを作る
using UnityEngine;
using System.Collections;
// ★追加
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour {
// ★追加
public Text timeLabel;
public float timeCount;
// ★追加
void Start () {
timeLabel.text = "TIME;" + timeCount;
}
// ★追加
void Update () {
timeCount -= Time.deltaTime;
// ToString("0")は小数点を切り捨て
// 小数点1位まで表示するにはToString("n1")
// 小数点2位まで表示するにはToString("n2")
timeLabel.text = "TIME;" + timeCount.ToString("0");
if(timeCount < 0){
SceneManager.LoadScene("GameOver");
}
}
}
![D37435b4 a2b7 4f03 9c9c 658d7da0bafe](https://codegenius.org/uploads/slide/image/519/d37435b4-a2b7-4f03-9c9c-658d7da0bafe.jpeg)
![Be157c4c b9bf 44d9 b4a0 6a9480d50f79](https://codegenius.org/uploads/slide/image/520/be157c4c-b9bf-44d9-b4a0-6a9480d50f79.jpeg)
![B396fb37 4439 486a 829b 6424507aaf0e](https://codegenius.org/uploads/slide/image/521/b396fb37-4439-486a-829b-6424507aaf0e.jpeg)
タイムアタックを作ろう/UIテキストの使い方