I have an array of game objects and an array of bools, I'm trying to instantiate the game objects if the bool is true but it's not working. Here's what I have so far... Code (csharp): public bool[] itemOwned; public GameObject[] items; int itemNumber = -1; public void setUpGear(){ foreach (GameObject item in items){ itemNumber += 1; if(itemOwned[itemNumber]){ //instantiate code here } else { break; } } Can anyone help please?
The whole post was rendered as html for some reason with all the tags showing. Basically: if ( itemOwned[itemNumber] == 0 ) /false/-1 Continue //Instantiate code here The 'Continue' command basically returns the loop back to the start of the next iteration if itemOwned[itemNumber] is equal to 0, or whatever value you use to check if it is false. if it is equal to 0 anything after the Continue command is skipped because Continue breaks out the loop and continues on to the next iteration.
Untested, but simpler / cleaner... Code (csharp): foreach (GameObject item in items) { itemNumber++; if (itemOwned[itemNumber]) { // Instantiate here } }