Queue a Coroutine with a List?
I have a script that displays notifications on-screen, the text fades in and out through Coroutines so I need both to of completed before displaying the next. I had the code setup but due to a power outtage I lost the script before I could save.
I was using a List to store all of the notifications and then displaying each one by one, making sure that I wasn't currently displaying one before playing the next. But I have no idea how I went about this and it's been frustrating me for the last day.
Does anyone have anything that might point me on the right track?
I just can't get past that story.
You forgot the basic idea about code you wrote. Code you just now wrote (since it wasn't even saved.) And you lost it in a power outage? So, a plugged-in computer with no battery?
And you wrote that down as part of your Q, because, I assume, you don't just want messages to display one after another. You're hoping to see some off-beat sub-optimal solution similar to what you did, which will give you the feeling of recovering a memory?
I remember the basic idea, but considering that I had no idea how to go about it in the first place it was a spur of the moment thing getting it to work. I'd lost it a week ago and have spent the last week trying to re-write what I did but have not yet gotten it to work again.
Yes, a computer that goes off in a power outage probably wouldn't have a battery, would it? Otherwise I wouldn't be posting this question.
Yes and it did. The answer below helped me to remember a part that I forgot in the code I have currently.
Answer by Hellium · Jun 22, 2016 at 09:22 PM
I haven't tested the following code, but it gives the idea :
void Start()
{
StartCoroutine( ProcessNotifications() ) ;
}
IEnumerator ProcessNotifications()
{
while( true )
{
while( notificationsList.Count > 0 )
{
yield return StartCoroutine( notificationsList[0] ) ;
notificationsList.RemoveAt( 0 ) ;
}
yield return null ;
}
}
Using a Queue
ins$$anonymous$$d of a List
would have been more efficient.
Your answer
Follow this Question
Related Questions
How do multiple objects in sequence from a queue? 0 Answers
Unit Production Queue Display 0 Answers
Enemy Database using list/dictionary to store stats (C#)? 1 Answer
Reset animation in animator when execution the same animation in row 0 Answers
InvalidOperationException: Operation is not valid due to the current state of the object 1 Answer