I’m trying to make an incremental game of sorts. As you may know, incrementing numbers is a huge part of this task and should be done as efficiently as possible. I’ve come across two seemingly similar ways to do this that both seem viable and popular. The first way is simply using a Coroutine and having it add a certain value after a yield return new WaitForSeconds(waitTime)
command. The second way is to just constantly add values using something like value += amount * Time.deltaTime
and putting it in the Update function. I’d like to know which would be less resource intensive since I’ll be adding tens to hundreds of these, or possibly a new way that is more efficient than both of my known methods. Any information on this topic would be great, as I have not found much in my search queries.
Edit: I thought I would also mention that I am programming in C# and would prefer any code given in C#, although I could transpose if need be.
Edit 2: I also realize you could call an InvokeRepeating()
call and simply pass in a function that adds a certain value at a set interval. I am still unsure of how any of these three methods compare in efficiency. Currently, it would seem that the Time.deltaTime equation would be the least resource intensive since it is just a simple equation rather than a whole function, but I am not too sure about that reasoning. At this moment in time, I will likely implement my incrementing functions using that equation and see how it goes. I will be using the general equation of:
value += (valueToAddEachInterval * (1 / timeInterval)) * Time.deltaTime;
This will allow me to increment a value by a certain amount in a given interval, such as 5 every 12 seconds. I am still eager to hear back from other users and the techniques they use for such implementations.