Question by
Gamepalast · Jan 03 at 10:47 AM ·
scripting problemscripting beginnertimerscene-switching
Safe Timer Score when changing scenes
Hi, I have a stopwatch that starts at level start. When you drive through the finish the time stops and it changes to another scene. How is it possible to show the stopped time in the other scene? Thanks for any help
This is my timer code :
public class Timer : MonoBehaviour {
public Text timerText;
private float startTime;
private bool finnished = false;
// Start is called before the first frame update
void Start()
{
startTime = Time.time;
}
// Update is called once per frame
void Update()
{
if (finnished)
return;
float t = Time.time - startTime;
string minutes = ((int)t / 60).ToString();
string seconds = (t % 60).ToString("f2");
timerText.text = minutes + ":" + seconds;
}
public void Finnish()
{
finnished = true;
timerText.color = Color.yellow;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051226im_/https://answers.unity.com/themes/thub/images/avi.jpg)