Z
Z
Zefirot2021-06-21 13:56:19
Unity
Zefirot, 2021-06-21 13:56:19

Does Time.deltaTime always equalize the total time?

Here in my prefabs I need to add a counter every second, let's say

private float TM = 0, TMSpeed = 1f;
private int Counter = 0;
void Update(){
  TM += Time.deltaTime;
  if(TM > TMSpeed ){
    TM = 0;
    ++Counter;
    }
  }

I pre-checked it by running several prefabs and it seems like it counts exactly and every second everywhere.
But will it be like this forever? Is it possible to use such a counter with confidence, will it always add a second (in this example), will the counter always be uniform on all prefabs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-06-21
@Zefirot

No. You will 100% be wrong.
Look, let's say deltaTime = 0.9
Then the values ​​in the update are 0.9, 1.8.
At 1.8 you will string, and then you will nullify the value and lose your 0.8 - almost a second!
But if we talk about "uniformity on prefabs" - then yes, update is called sequentially for all active objects, and everyone will have the same deltaTime - the time of the PREVIOUS frame (please note, not the current one), and until all objects are updated - the next frame will not start.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question