Best way to queue animations (coroutines)
Hello, In my project, I am retrieving data called states from an outside source. I can get up to 3 states per second. My goal is to the following:
Each state will run an animation
An animation should wait for the previous one to finish before running.
For that goal I am planning to do the following, and I'm looking for advices or improvements on this logic in case it is needed.
When a state is retrieved, put it in a queue
Have a main coroutine running all the time (while true). This main coroutine has a boolean called isAnimationRunning
The main coroutine will check the queue, if it has a state and isAnimationRunning=false then it dequeue a state, create the animation coroutine for it, and start it.
The animation coroutine will perform the animation then set isAnimationRunning to false, in order for the main queue to dequeue the next state
Is this a good approach or there is a better way?
Some alternatives:
Use the Update function instead of the main coroutine. Will that cause a problem/improvement?
Instead of queuing the **states*, I queue the animation coroutines, and run one after the other.
Instead of having the main coroutine running all the time, I only run it when there is states in the queue. Once the queue is empty, I stop it, and start it again as soon as I get a new state
Thanks a lot for any input, validation, or improvement on this.
Edit: For clarification, I have to use a coroutine because I'm also doing a post animation logic.