Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Breaking out of the right loop

$
0
0
im trying to only add a card to my hand if it doesnt already exist, this is the code i use: public List playerHand = new List(); public void LoadCards () { Debug.Log("Loading Cards!"); for (int i=0; i < this.transform.childCount;i++) { foreach (Card card in playerHand) { if (this.transform.GetChild(i).GetComponent() == card) { break; } } playerHand.Add(this.transform.GetChild(i).GetComponent()); } } The problem is that my break just brings the loop back to the foreach, while i need it to go back to the for loop to make sure i dont add dublicate cards

Viewing all articles
Browse latest Browse all 184

Trending Articles



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