Score Reset on 2nd Play
This script is supposed to set a text gameobject to count down when the play button is hit on the start screen, count down from 25 while the user is attempting to win, and switch to the lose screen when the time is reduced to 0. Then, the lose screen should go back to the start, where the user could play. What the script does now is exactly the same, but once the user wins, the score stays the same and skis straight to the lose screen when you click play. using UnityEngine; using System.Collections; using UnityEngine.UI;
public class countdownTimer : MonoBehaviour { public Text score; public GameObject countdownManager; public bool endGameBool = false;
void Awake()
{
DontDestroyOnLoad(countdownManager);
DontDestroyOnLoad(score.transform.root.gameObject);
}
void Update()
{
setTime();
}
void setTime()
{
float timeSinceStart = Mathf.Round(Time.time);
float scoreText = (25 - timeSinceStart);
if (scoreText > 0) {
score.text = (scoreText.ToString());
}
else
{
score.text = ("0");
endGameBool = true;
scoreText = 25;
`` }
} }
Does anyone know how to reset the score when the user restarts the game?
Answer by Quertie · May 30, 2016 at 09:07 AM
You could try using Time.timeSinceLevelLoad instead of Time.time ! And then just reload the scene if you want to restart! ;)
That would not work. Every time the player moves on to the next level, the time resets. I want the time to keep counting when the scene switches. I want to bring the time back to 25 when the text hits 0.