Hello, I’m pretty new to Unity and I’m trying to do something with coroutines.
I’m doing like a dialog game. First character speaks, then answers are shown and when I click, 2nd character speaks.
So let me explain my problem : i display text letter by letter (that’s why I use coroutines). But when I’m still displaying text of my 2nd character, the text of the 1st character starts displaying aswell ( his next text).
How can I do to make first coroutine starting after 2nd coroutine finished his job ?
You may want to have a look at my WaitForUIButtons which I created for this question over here. It’s essentially just a small custom yield instruction that will register itself to the onclick event of the specified button and will resume the coroutine when that click happened. You can wait for multiple different buttons at once to provide a choice for the user. It also provides you the actual button that was clicked when it resumes. You can also specify a callback when a button has been pressed. So this class can also be used to easily attach a one-time event to a button that removes itself once executed.
I would highly recommend to not use too many coroutines / nested coroutines. It’s generally better to have one coroutine and maybe another nested level if really necessary to handle such sequential logic.