I need help. i dunno how to explain but its like this

if animal ‘a’ is respawn, the next respawn is ‘b’ or ‘c’ ,
if animal ‘b’ is respawn, the next respawn is ‘a’ or ‘c’ ,
if animal ‘c’ is respawn, the next respawn is ‘a’ or ‘b’
IEnumerator SpawnAnimal(float time){
yield return new WaitForSeconds (time);
Vector3 temp = transform.position;
temp.x = Random.Range (x1, x2);
Instantiate (animals [Random.Range (0, animals.Length)], temp, Quaternion.identity);
StartCoroutine (SpawnAnimal (Random.Range (4f, 5f)));
}
Good Day and thanks before
Try this code…
public class Spawner : MonoBehaviour
{
[SerializeField] private float spawnRate;
[SerializeField] private GameObject[] prefabs;
private int lastIndex = -1;
private float counter;
private void Update()
{
if (counter >= spawnRate)
{
Spawn();
counter = 0f;
}
counter += Time.deltaTime;
}
private void Spawn()
{
if ((lastIndex + 1) < prefabs.Length)
{
lastIndex += 1;
}
else
{
lastIndex = 0;
}
Instantiate(prefabs[lastIndex], position, rotation);
}
}