UnityとC#でゲームを作っています。
ゲームシーンからリザルトシーンに移った時に、リザルトシーンにゲームクリアにかかった時間を表示したいのですがその方法が分かりません。
どこにどのようなプログラムを書けば良いのでしょうか?
ゲームシーンで時間を表示するスクリプトはこう書いています。
public class Timer : MonoBehaviour {
private int minute;
private float seconds;
private float beforeSeconds;
private Text timerText;
// Use this for initialization
void Start () {
minute = 0;
seconds = 0f;
beforeSeconds = 0f;
timerText = GetComponentInChildren<Text>();
}
// Update is called once per frame
void Update () {
seconds += Time.deltaTime;
if (seconds >= 60f)
{
minute++;
seconds = seconds - 60;
}
// 値が変わった時テキストを更新
if ((int)seconds != (int)beforeSeconds)
{
timerText.text = minute.ToString("00") + ":" + ((int)seconds).ToString("00");
}
beforeSeconds = seconds;
}
}
リザルトのシーンに移るプログラムはPlayerのスクリプトにSceneManager.LoadSceneを使っています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。