Modulus Question

If I’m using modulus inside of update like so:

if(Time.time % 3 == 0)
{
Debug.Log(“Print some stuff”);
{

why would this only trigger one time (at 0)? Are the Time.time intervals based on frames or am I missing something else? It’s been a while since I’ve used modulus.

Thanks!

Time.time is the time since the game started. See the documentation

It’s a float, so the result of Time.time % 3 will almost never be 0. You should perhaps round the value to an integer.

if (Mathf.RoundToInt(Time.time) % 3 == 0)
{
    Debug.Log("Print some stuff");
}

This makes a lot of sense. Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms