Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

Best practise time-based, repeating function calls: InvokeRepeating vs CustomSolution

$
0
0
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? **

Viewing all articles
Browse latest Browse all 220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>