Timer Starts Too Early

Hi, I am still fairly new to unity and need help with a timer I have in my simple racing game. The Timer is just a UI Canvas that Displays 00:00 at the top of the screen, and has a script attached to it that counts up in seconds and minutes. The Problem is, I have 5 levels (Start Screen, Tutorial, Level 1, Level 2, and Level 30. Level 1 (where I want the timer to actually start counting, is build index number 2. Right now, the timer starts counting at build index 0, which is my Start Screen. meaning that if you sit at the starting screen for 5 minutes before clicking start, once you get into the game, you will already have a time of 5 minutes even though you just started playing. I will attach the code I used for my timer below.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Timer : MonoBehaviour {

    public Text counterText;

    public float seconds, minutes;
	// Use this for initialization
	void Start ()
    {
        counterText = GetComponent<Text>() as Text;
	}
	
	// Update is called once per frame
	void Update () {
        minutes = (int)(Time.time / 60f);
        seconds = (int)(Time.time % 60f);
        counterText.text = minutes.ToString("00") + ":" + seconds.ToString("00");
	}
}

Sorry I know I’m not great at explaining things. But it comes down to this, right now the timer starts on build index 0, and counts continuously through each level after that. However I want the timer to start counting when the program reaches build index 2, which is the true Level 1 of the game.

Thanks a lot!!!

using UnityEngine.SceneManagement;

        ...
        public float _startTime;
        public int buildIndex;
        
        if (buildIndex >= 2)
        { _startTime == Time.time;
    minutes = (int)(Time.time - _startTime / 60f)}

This solution may need modifying if Pausing or dilation of time occurs but want to offer an alternative solution.


Use a static Timer class (see code) that just holds a DateTime varible.

    using System;
    using UnityEngine;
    using UnityEngine.UI;

    public class Level1StarterObject
    {
      void DoSomthing()
      {
        Timer.ResetTime();
      }
    }

    public class TimerVisualiser : MonoBehaviour
    {
      public Text counterText;

      void UpdateVisuals()
      {
        TimeSpan? span = Timer.GetTimeSpan();

        if (span.HasValue)
        {
          counterText.text = string.Format("{0:00}:{1:00}", span.Value.Minutes, span.Value.Seconds);
        }
      }
    }

    public static class Timer
    {
      private static DateTime? startTime;

      public static bool IsTimeSet()
      {
        return startTime.HasValue;
      }

      public static void ResetTime()
      {
        startTime = DateTime.Now;
      }

      public static TimeSpan? GetTimeSpan()
      {
        if (IsTimeSet())
        {
          return (DateTime.Now - startTime.Value);
        }
        return null;
      }
    }