- Home /
Yield in sequence inside a loop?
Hello everyone, I'd like some help to understand the following code. I got the following cards inside the scene.
With the following code, I try to make the cards switch of positions.
for (int i = 0; i < oNoSwitches; i++) {
//Debug.Log ("Cambio de cartas numero: " + (i + 1));
yield return switchCards();
}
At first I thought the methods will be called one by one, waiting for the card switching to finish, but It doesn't go that way, instead the cards start to move randomly after some amount of time and doesnt wait for the cards to finish moving like I thought it would, How can I fix this? Thanks in advance
Answer by Pengocat · Dec 20, 2016 at 02:07 PM
You could add a while loop that prevents the Coroutine from falling instantly into switchCards(). Without any other type of yield or a yield and a while loop it will all happen in one frame.
Your answer
Follow this Question
Related Questions
How to have a (wait) yield on a for loop? 0 Answers
Using Loops 1 Answer
Having Trouble with this For Loop 1 Answer
For loop going based off of Time.deltatime? 1 Answer
Adding an object to an array only if it is not in the array 2 Answers