Need Stopwatch Timer for my game

Hello, so I’m currently working on a fast paced parkour game and I would like to add a stopwatch timer of sorts. By stopwatch I mean just counts up. Now I already have one however it doesn’t include the milliseconds and I would like that as my game is on speedrun.com.

If anyone knows a Unity Asset Store item thing (for free as i don’t have money), if you know a tutorial on like youtube or something or a actual script.

Thanks!


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

there, the timer will count up.

Or use the built in c# stopwatch

You’re making a ‘fast paced parkour game’ and can’t figure out how to add a stopwatch that includes milliseconds?

You may want to assess whether you can actually do that with your current skill set. Try making something simple like Pong first and go from there.

2 Likes

listen mate i’ve already done most the game, i just wanted to know the most effective timer. you don’t gotta say that. either way i’ve done it

The most effective timer is accumulating the factual delta time between the frames.

Obviously you want to accumulate time in a 64-bit float, otherwise accuracy is gone after several minutes, because 32-bit float quickly loses precision after 4 integer digits or so, where 64-bit float can store up to a month or so of continuous play time.

The reason why you’d want to accumulate the delta time is because that’s the only thing that is in sync with your game and stays true to your rendering tempo. The other reason is because this is the only thing that is available from inside Unity.

Unity exposes timeAsDouble and realtimeSinceStartupAsDouble for this purpose, though you can also do your own measuring.

Measuring length between two points in time is also possible however consider that a stopwatch should not be frame-independent. Especially when it comes to speedrunning.

1 Like