public void UpdateBranch() { //go through our active bolts for (int i = boltsObj.Count - 1; i >= 0; i--) { //get the GameObject GameObject boltObj = boltsObj[i]; //get the LightningBolt component LightningBolt boltComp = boltObj.GetComponent <LightningBolt>(); //update/fade out the bolt boltComp.UpdateBolt(); //if the bolt has faded if (boltComp.IsComplete) { //remove it from our list boltsObj.RemoveAt(i); //destroy it (would be better to pool but I'll let you figure out how to do that =P) Destroy(boltObj); } } }
public void UpdateBranch() { for (int i = boltsObj.Count - 1; i >= 0; i--) { GameObject boltObj = boltsObj [i]; LightningBolt boltComp = boltObj.GetComponent <LightningBolt> (); boltComp.UpdateBolt(); if (boltComp.IsComplete) { boltsObj.RemoveAt(i); Destroy(boltObj); } } }