K
K
KpacaB4uK2017-08-21 17:10:53
C++ / C#
KpacaB4uK, 2017-08-21 17:10:53

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

1 answer(s)
D
Denis Gaydak, 2017-08-21
@KpacaB4uK

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 question

Ask a Question

731 491 924 answers to any question