I watched a tutorial in YouTube about creating a countdown timer. It works well. Problem is, the timer still keeps going even when it reaches 0.
How do I restart the scene when the timer hits 0?
HERE’S THE TUTORIAL I WATCHED: [Unity 4] Creating a simple countdown timer (JavaScript) - YouTube
EDIT : I mixed up c++, c# and java, change the first line to import UnityEngine.SceneManagement;
I copied the script from the video, just add 2 lines of code
#include UnityEngine.SceneManagement; //include this to use the SceneManager
function Update()
{
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
//You can restart the scene here
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
What SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
does is get the current scene and load it again, which simulates a ‘restart’ of the current scene