IEnumerator: if/else: breaking cycle

Hi there,
Sorry to ask this, but with in a coroutine, I have an if/else statement. What I am wondering is, no matter what I try, I can not seem to “return” out of either if true or if false.

//On Mouse click  


 ///Case 1A. active piece == hit transform
 if(tf_activePiece == hit.transform){
 print("1A");
 //potenial moves is active,hide them
 if(isPotentialMoves_active){
 print("1Aa");
 hide_PotentialMoves();
 }
 //potential moves is inactive,show them
 else if(!isPotentialMoves_active){
 print("1Ab");
 show_PotentialMoves();
 }
 }

No matter what I do, with one mouse click, both 1Aa and 1Bb are printed. So both cases are called. How do I break the cycle? “return”, “return null”, “return true”, “return false”, “yield return null”, “break”, and creating a case scenario have fallen short for me.

Any tips?
Thanks

You can’t return a bool from a coroutine. Break is for loops.

What does hide_PotentialMoves() do?

You might want to show your entire coroutine so we get a better idea of what is going on.

Also might be helpful to know how you are calling the coroutine.

I only mention these because based on your if statement, there is nothing wrong.

“yield break” will stop the coroutine immediately.

1 Like

Thank you!