Quantcast
Viewing all articles
Browse latest Browse all 16

Re-using the "same" for loop?

In function Update(), I'm looping through my GameManager's player array to check for conditions. The problem is I need to do this in multiple places, which requires me to use differently named variables for each loop(haha, "for each loop"). For example: function Update() { if(winnerWasHooked == false) { for(var w : GameObject in winningPlayers) { if(w.GetComponent(WeapGrapple).hookedObject == null) { raceCamScript.DisplayMessage("HOOKED!", Color.white, true); break; } } } else if(winnerWasDetermined == true) { for(var v : GameObject in winningPlayers) { if((v.GetComponent(Player).hasAchievedDeflection == true) && (deflectionMessage == false)) { deflectionMessage = true; matchRestartTimer = Time.time + 3.0; raceCamScript.DisplayMessage("FULL DEFLECTION!", winningColor, true); } } } } Is there a way I could make a function that returns each GameObject in my player array without the function breaking on the first iteration? I tried using "yield" instead of "return", but the compiler got angry at me. I know there HAS to be a clean way to do this. I may even be approaching this entirely wrong. Thanks.

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>