Countdown timer in multiple scene?
I have a code below for countdown in a scene. But can I use this code in a multiple scene? Player have 3 levels(3 scene) and they need to finish all levels in 2 minutes. If player did not finish all 3 levels in 2 minutes, then it will load exit page.
I think it would not necessary to put in text for this situation. Can anybody give some examples of code in C#
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class timer : MonoBehaviour {
 
     public GameObject timeTF;
     public GameObject alertReference;
 
     void Start () {
         timeTF.GetComponent<Text>().text = "120";
         InvokeRepeating("ReduceTime", 1, 1);
     }
     void ReduceTime()
     {
         if (timeTF.GetComponent<Text>().text == "1")
         {
             Application.LoadLevel("gameover");
         }
         
         timeTF.GetComponent<Text>().text = (int.Parse(timeTF.GetComponent<Text>().text) - 1).ToString();
     }    
 }
 
Answer by mikelortega · Feb 19, 2016 at 08:04 AM
Put your script in the first scene, only in the first one, and mark it it with DontDestroyOnLoad at Start. This way, when you load a new scene the counter will not be destroyed and it will follow counting.
so I put this code in.
 void Start() {
         DontDestroyOnLoad(transform.gameObject);
     }
but it doesn't do anything
I know why It does not work. Because my object is in 2D, and it put under canvas. As far as I know is DontDestroyOnLoad will not work if its a child. Only parent right?
Your answer
 
 
             Follow this Question
Related Questions
Start and Stop Timer Help 1 Answer
Countdown timer... 2 Answers
Need to create a Time Trial in Unity with C# 1 Answer
Player Countdown Interaction/Time Reduction+Addition 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                