Hi,
First of all, thanks for any answer that I might (or might not!) get in this thread. I’ve recently started using Unity and completed the “roll a ball” tutorial.
I’ve added a basic timer script that will count from 30 to 0 and reload the level when 0 will hit.
I’d like to add a basic “You lost!” text and reload the level after 5 seconds (or so), but I can’t seem to be able to correctly add the Coroutine and the subsequent WaitForSeconds inside an “if timer hits 0 then…”.
Below is my very basic code for the timer:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
public class myTimer : MonoBehaviour {
public float myTimer = 30;
public Text timerText;
// Use this for initialization
void Start () {
timerText = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
myTimer -= Time.deltaTime;
timerText.text = myTimer.ToString ("f0");
print (myTimer);
if (myTimer <= 0) {
SceneManager.LoadScene (0);
}
}
}
Thank you all for your help!