Coroutine only working when waiting 0 seconds

I want to call a method 10 times, with a time difference of one second. But my method is only beeing called once, when i yield return new WaitForSeconds with a value bigger than 0


My Code:

IEnumerator MyMethod(int number)
{
    int i = 0;
    while (i < number)
    {
        //Do something

        //yield return new WaitForSeconds(1.0f);  -My goal, but not working
        yield return new WaitForSeconds(0); - Working
        i++;
    }
}

Hello.

You dont want to use a while there.

For your code, i understand you are stille learning, I strongly recommend to not use while function. While fucntion makes the code stay inside, causing infite loops if are not set perfectly.

Do this (declare the variables outside the function):

int i = 0;
int thenumber = number

IEnumerator MyMethod()
 {     
     if (i < number)
     {
        //do things
        yield return new WaitForSeconds(1.0f);
        i++;
        StartCorutine(MyMethod());
     }
 }

Bye! ;D