Answer the question
In order to leave comments, you need to log in
c#Unity coroutine doesn't work, what's the syntax error?
void Start()
{
print("wait..");
StartCoroutine(Sec()); // Why doesn't it wait 5 seconds?
print("5 seconds later"); //Displayed immediately
}
.............................................. .......................
IEnumerator Sec()
{
yield return new WaitForSeconds(5f);
}
Answer the question
In order to leave comments, you need to log in
void Start()
{
print("wait..");
StartCoroutine(Sec()); //запустили коронтину и тут же вернули управление в основной поток
print("5sec later"); //само собой сразу выполнится все что после запуска короунтины
}
....................................................................
IEnumerator Sec()
{
print("start coroutine"); //Выводится сразу
yield return new WaitForSeconds(5f);
print("5sec later"); //через 5 секунд
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question