In my game you have 2 minutes to finish the whole game and after searching for an answer to my problem I think I should use DontDestroyOnLoad
but I can't understand how to use it correctly. Here's the code:
public class countdownTimer : MonoBehaviour {
public float myTimer = 120;
public Text timerText;
private bool timerIsActive = true;
void Start () {
timerText = GetComponent<Text> ();
}
void Update () {
if (timerIsActive) {
myTimer -= Time.deltaTime;
timerText.text = myTimer.ToString ("f0");
print (myTimer);
if (myTimer <= 0) {
myTimer = 0;
timerIsActive = false;
SceneManager.LoadScene ("lose");
}
}
}
}
}