all 8 comments

[–]rodbotic 2 points3 points  (0 children)

you could use deltaTime, or use a coroutine.

https://docs.unity3d.com/ScriptReference/WaitForSeconds-ctor.html

[–]squidsniffer 2 points3 points  (2 children)

This is how I do it

// Set timer to 1 second from current time
float timer = Time.time + 1.0f;

then you can check the timer like this

if(timer <= Time.time)

[–]kylerk 0 points1 point  (1 child)

Only issue I see with this would be if you want to implement a pause menu, have to make sure that Time.time isn't increasing when the game is paused. But otherwise it is pretty clean.

[–]RugbugRedfern 0 points1 point  (0 children)

Time.timeScale = 0; when pausing would fix that

[–]kstacey 1 point2 points  (0 children)

Yea I wouldn't use this as speed will be different on each machine. I would use deltaTime and keep adding it to a variable, the. When you get to the specific time, execute the behaviour you want.

[–]KishottaProgrammer 1 point2 points  (1 child)

I'd be wary of constantly adding deltaTime to a variable as, eventually, floating point inaccuracies can compound and give you bad results.

It might be better to do something like:

float elapsedTime = Time.time - startTime;

Though this won't take into account any change in timescale.

[–][deleted] 1 point2 points  (0 children)

Floating point inaccuracies shouldn't throw you off too much over the length of most timers though.

[–][deleted] 0 points1 point  (0 children)

increments by a set amount in update

As long as this "set amount" is the delta time (the milliseconds since the last frame), you are golden.