How do I make a timer?

I am trying to make a spawner that will spawn objects after fixed time intervals. How do I do this?
I am using C#. Thanks

I managed to find a solution, but I don’t know if this is the most optimal solution.

            frameCounter++;
            if ((frameCounter)%120 == 0)
            {
                Debug.Log("lol");
            }

Not sure if my solution is any better, but I typically use something like this:

spawnTimer += Time.DeltaTime;

if (spawnTimer >= 2)
{
    Debug.Log("lol");
    spawnTimer = 0;
}

The benefit of doing it this way is that the timer remains framerate independent.

2 Likes

Thank you!

1 Like