Events over Time Standard Procedure

I’m having events happen based on Time (so for example, every 20 minutes, something happens), and was wondering if there’s a standard procedure for this. I know that I can check the time, and execute coroutines accordingly, but was wondering if there’s a really clean way to do this in Unity that doesn’t invite bugs (I’m a little nervous since I doubt I’ll be able to thoroughly playtest long game sessions).

As long as everything is using Time.deltaTime, you can actually playtest long game sessions in a short amount of time by increasing the Time.timeScale. The easiest way to do what you want would be a coroutine:

private IEnumerator ReoccuringTimedEvent(float interval)
{
    var waitEvent = new WaitForSeconds(interval);
    while (true)
    {
        yield return waitEvent;
        DoAThing();
    }
}
2 Likes