Question by
Ephenodrom · Oct 04, 2017 at 08:46 AM ·
c#coroutine
Display multiple Text in a row for a certain time
Hello,
I got a list field, containing certain strings. Now I want to display each string for a fixed amount of time. A string should only be displayed if the previous string was displayed.
for(String s : list){
StartCoroutine(displayText("2.0f");
}
IEnumerator displayText(float waitTime) {
// display the text ...
yield return new WaitForSeconds(waitTime);
// display = false
}
The problem is, the for loop continues and doesn't wait 2 seconds for the next loop.
Any ideas how to fix that ?
Greetings
Comment
Best Answer
Answer by Hellium · Oct 04, 2017 at 09:00 AM
Try this :
StartCoroutine( displayTexts() ) ;
// ...
IEnumerator displayTexts()
{
for(String s : list){
yield return StartCoroutine(displayText("2.0f");
}
}
IEnumerator displayText(float waitTime) {
// display the text ...
yield return new WaitForSeconds(waitTime);
// display = false
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612140236im_/https://answers.unity.com/themes/thub/images/avi.jpg)