How to add float (seconds) to a TimeSpan behaving like a stopwatch?

I made a stopwatch for my racing game, and I also want to add time penalties when player does something wrong (e.g. cutting corners too much), but I couldn’t get it to work.

Here is the stopwatch code running in a loop, works perfectly:

TimeSpan time = TimeSpan.FromSeconds(currentTime);
stopwatch.text = time.ToString("mm':'ss':'fff");

Now I just want to add a time penalty, to make it clear I want the timer to go from 00:18:200 to 00:28:200 instantly with a 10 second penalty.

How can I achieve this?

TimeSpan has an operator+ and operator- overload , in other words you can do stuff like

TimeSpan a = TimeSpan.FromSeconds(10);
TimeSpan b = TimeSpan.FromSeconds(12);
TimeSpan c = a + b; // <- this will be 22 seconds
TimeSpan d = a - b; // <- this will be -2 seconds

so in your case, just do something like this

time += TimeSpan.FromSeconds(10); // apply penalty