- Home /
Why are Objects not getting destroyed?
First of all the code:
public void regenerateLevel(){
obstacles = GameObject.FindGameObjectsWithTag("Obstacles");
//Delete obstacles
for(int j = 0; j <= obstacles.Length; j++){
Destroy(obstacles[j]);
obstacles[j] = null;
}
//Generate new obstacles
for(int i = 0; i <= 4; i++){
rand = Random.Range(0, 2);
if(rand == 0){
Instantiate(obstacle, spawnpoint[i].transform);
}
}
}
First problem is, that the objects only get destroyed in like the first 2 times this function runs. The other problem is, that the array containing all the objects will keep on expanding after those 2 times. Hope you guys can help me!
Comment