My Timer stops when loading new scenes
Hi it's my first time posting here, I have a problem concerning my Timer that is stored in a UI Text which is stored in a game object, I have DontDestroyOnLoad on this game object, however when I try to load other scenes while running the application, my timer just stops and stays frozen, here's my timer script:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public Text timer;
private float startTime;
void Start () {
startTime=Time.time;
}
void Update () {
float T=Time.time - startTime;
string minutes = ((int) T / 60).ToString();
string seconds = (T % 60).ToString();
timer.text=minutes + ":" + seconds;
}
}
Could someone help me please?
Comment
Answer by ChaHaj · Aug 14, 2017 at 11:16 AM
I found the problem it was
startTime=Time.deltaTime;
Instead of
startTime=Time.time;
Your answer
![](https://koobas.hobune.stream/wayback/20220612132700im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Playing a sprite animation before an object is destroyed 0 Answers
camera falling down when following player!! 1 Answer
unity 5 car traffic system 0 Answers
How to reference script in unity (C#) ? 0 Answers
Unity 2d Collision Glitch Help 0 Answers