I recently started work on a strategy game, which is very similar to games like ANNO, CIVILIZATION and SETTLERS.
----------
For this I had to write a lot of functions which repeat each X seconds, e.g. worker requesting resources, taxes ticking every minute etc.
I solved this the following way:
private float repeatingIntervalInSeconds = 15;
private float timeSinceLastCall;
private void Update()
{
timeSinceLastCall += Time.deltaTime;
if(timeSinceLastCall >= repeatingIntervalInSeconds)
{
timeSinceLastCall -= repeatingIntervalInSeconds;
functionCall();
}
}
This however adds a lot of boilerplate.
Now I read about [InvokeRepeating](https://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html) but also read that it involves some overhead.
**Is there another better way I overlooked or is it fine to use InvokeRepeating? **
↧