What i am trying to achieve is have a list of prefabs(different kinds of ammo if you will) and i want at the start of a scene instantiate the first item on the list. After it is destroyed i want to spawn the next item on the list. Any help would be much appreciated.
There are two ways to achieve this, one is keep a track of the index (position) in the list, or use a queue.
public List<AmmoTypes> ammoList = new List<AmmoTypes>();
private int ammoListPosition = 0;
void Start(){
StartCoroutine(SpawnAmmo());
}
IEnumerator SpawnAmmo(){
while (true) {
if (someway to check ammo is not spawned ammoListPosition <= ammoList.Count) {
SpawnThisAmmo(ammoList[ammoListPosition]);
ammoListPosition++;
}
if (ammoListPosition > ammoList.Count)
{
//We have used all items, reset it here if you want
ammoListPosition = 0;
}
yield return new WaitForSeconds(0.5f); //Check every half a second
}
This is untested and is just for an example only
Thank you, trying it now.