DontDestroyOnLoad causing update to not work in next scene?

So I have an object on a timer. The timer goes between scenes. The timer counts down using :

 private void Update()
    {
        timer -= Time.deltaTime;
    }

In the original scene, the timer counts down as its supposed to however when it transitions to the next scene using DontDestroyOnLoad the timer resets to the original value and does not countdown. The rest of the script works fine in the next scene, it just seems like Update is not working and I can’t figure it out.

1 Answer

1

Have you tried setting your “timer” as static?

That was it thank you. I'm still a rookie at c#, would you mind explaining why changing that variable to static fixed it?