Using if statement inside IEnumerator freezes unity
Okay so here is the code
IEnumerator LookingForTarget() { for (;;) { if (TargetsCount > 0) { ShootingState(); StopCoroutine("LookingForTarget"); } else { yield return new WaitForSeconds(.5f); } } }
In the game, whenever someone is at the player´s range, it goes into that "targets" list. By using this code i wanted to control the reaction time of the player so he´s not actively looking for a target all the time. But when i run unity everything goes nice until a target its at range, because unity freezes. I´ve been putting different Debug.Log´s in the code to see where the program stops and it seems like anything i write after that if statement is not executed if the statement is true... Thanks in advance
Your answer

Follow this Question
Related Questions
Implementing Neural Network into Unity. Lots of calculations. 0 Answers
AssetBundle LoadAllAssetsAsync freeze Unity Editor 5.3.3p2 (64-bit). 0 Answers
Unity freezes when I juggle Lists and SortedLists. 1 Answer
Rigidbody changes position when I add torque. How do I stop this? 1 Answer
How to fix editor freezing after code change? (during build) 0 Answers