using UnityEngine; using UnityEngine.UI; using System.Collections; public class TimeScript : MonoBehaviour { // Text timeText; FlagManager flag; [SerializeField] float time = 60f; private int minite, Second; void Start () { //コンポーネントを取得 timeText = GameObject.Find("Timer").GetComponent(); flag = GetComponent(); //float型からString型に変換して表示 timeText.text = (time).ToString(); StartCoroutine(timeCount()); } void Update() { /* //制限時間の処理 if (time > 0f) { time -= Time.deltaTime; minite = (int)(time / 60); Second = (int)time - 60 * minite; timeText.text = (minite).ToString("00") + (":") + (Second).ToString("00"); } else if (!flag.timeOver) { flag.timeOver = true; } */ } IEnumerator timeCount() { //制限時間の処理 while (time > 0f) { time -= Time.deltaTime; minite = (int)(time / 60); Second = (int)time - 60 * minite; timeText.text = (minite).ToString("00") + (":") + (Second).ToString("00"); yield return null; } if (!flag.timeOver) { flag.timeOver = true; } } public float getNowTime() { return time; } public void setTimeDebug(float t) { time = t; } }