Not execute after Yield return new WaitForSeconds
I want to call "makesomething(GameObject)" function for 10 different objects, and I call it in a for loop. But in the called function, codes after yield does not work. What is wrong with this codes?
xfunction();
void xfunction()
{
for (int j=0;j<10;j++)
{
GameObject back=GameObject.Find ("obj" + j);
StartCoroutine(makesomething(back));
}
}
IEnumerator makesomething(GameObject b)
{
yield return new WaitForSeconds(1.0F);
Debug.Log ("Not execute here anyway why?!!!");
}
Yes I call the function "xfunction()", if I write something before yield, it works, but anything after yield is not working:(
I have the same problem. Shame no one answered it yet. $$anonymous$$aybe this approach is wrong and we should put our code after WaitForSeconds method somewhere else?
@oguz1ak I have the same problem did you fix it?
Answer by tormentoarmagedoom · Jan 30, 2019 at 09:04 AM
I'm not a super expert, but i can talk about my experience using IEnumerators. Some things to try:
yield return new WaitForSeconds(1f);
(not capital F)
Are you sure the method is beeing called?
And as you are calling the methid from a loop, is possible it is called several times before that 1 second. So do another Debug.Log before the yield command saying the object "b" that has been called like:
IEnumerator makesomething(GameObject b)
{
Debug.Log ("Called using "+b.name);
yield return new WaitForSeconds(1);
Debug.Log ("Not execute here anyway why?!!!");
}
Lets see what you get!
Good luck! Bye!
Your answer
![](https://koobas.hobune.stream/wayback/20220612071253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Question to WaitForEndOfFrame 2 Answers
Trouble with Co routines & WaitForSeconds 0 Answers
EInumerator dont stop velocity I need 3sec to breake.. pls help 0 Answers
yield ends method 0 Answers