timer that continues through all scences

So we have a 2D side scroller game using c#. basically your score is how fast you can complete the game. We have a timer script that displays the time but it restarts when it changes to the next level. Also at the end of the game we want the win screen to be able to display your final time! Any help/clues as to how when can achieve this would be great! Thanks!

You probably want to use DontDestroyOnLoad for this.

Add DontDestroyOnLoad(this) to the Start() or Awake() function of the script that tracks the score. DontDestroyOnLoad(object) will make sure that the gameobject doesn’t get destroyed when you load another scene. Just remember that all other variables on the script, and all other components on the gameobject that has your script, also don’t get destroyed.

Call on the DateTime class to see what is the time and record it in a static variable. Then check what is the new time and compare and store:

private static DateTime ? previous = null;
void Start()
{
   if(previous != null)
   {
       DateTime now = DateTime.Now;
       // Compare now with previous using milliseconds or second or minute
       previous = now;
   }
}