I want to instantiate a random prefab after one of them is destroyed, but I don’t know how to declare that a prefab has been destroyed. So far, I have the prefabs set in a list, but now I’m completely stuck. Here is my code as of right now:
List<GameObject> prefabList = new List<GameObject>();
public GameObject Prefab0;
public GameObject Prefab1;
public GameObject Prefab2;
public GameObject Prefab3;
public GameObject Prefab4;
void Start()
{
prefabList.Add (Prefab0);
prefabList.Add (Prefab1);
prefabList.Add (Prefab2);
prefabList.Add (Prefab3);
prefabList.Add (Prefab4);
spawn ();
}
void spawn(){
int prefabIndex = UnityEngine.Random.Range(0,5);
Instantiate(prefabList[prefabIndex]);
}
}