How do I stop 'timeSinceLevelLoad' without pausing entire game?

I have been using timeSinceLevelLoad to make a stopwatch score counter. When the game ends I want it to freeze the counter so that I can show the player their final score. When I use Time.timeScale = 0F; it pauses the timer but I need the rest of the game to continue instead of freezing entirely. How would I go about pausing the timeSinceLevelLoad without freezing everything else?

Thanks in advance!

I don’t think you can. You have to use deltaTime and accumulate it only when the game is not paused or do something like this.

float playedSec;
float pausedSec;
bool isPaused;

void SetPaused(bool pause) {
   if (pause && !isPaused) {
      playedSec += Time.timeSinceLevelLoad - pausedSec - playedSec;
   } else if (!pause && isPaused) {
      pausedSec += Time.timeSinceLevelLoad - pausedSec - playedSec;
   }
   isPaused = pause;
)

Time.realtimeSinceStartup is not affected by time scale. This however does start from when your program was first loaded.

So…

What you could do is: Record the Time.realtimeSinceStartup at the start of each level load. Then split the difference to determine how much time was spent on the specific level.

void Start()
{
LevelLoadedTime = Time.realtimeSinceStartup;
}

void Update()
{
TimeSpentOnLevel = LevelLoadedTime - Time.realtimeSinceStartup;
}