Before Rick showcased his method I did the challenge myself almost exactly as he did although I ended up making an attacker type variable that was defined as the attackerPrefabArray and it’s range being random between 0 and the prefab Length
But i can see that what Rick did was make an index variable that was random between 0 and the attackerPrefabArray Length and then wrote attackerPrefabArray and put his new index variable inside the array parameter.
I suppose both methods are equally valid yes?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttackerSpawner : MonoBehaviour
{
bool spawn = true;
[SerializeField] Attacker[] attackerPrefabArray;
[SerializeField] float waitTimeMinimum;
[SerializeField] float waitTimeMaximum;
// Start is called before the first frame update
IEnumerator Start()
{
while(spawn)
{
yield return new WaitForSeconds(Random.Range(waitTimeMinimum, waitTimeMaximum));
SpawnAttacker();
}
}
private void Spawn(Attacker newAttacker)
{
Attacker attacker = Instantiate(newAttacker, transform.position, Quaternion.identity) as Attacker;
attacker.transform.parent = transform;
}
void SpawnAttacker()
{
Attacker randomAttacker = attackerPrefabArray[Random.Range(0,attackerPrefabArray.Length)];
Spawn(randomAttacker);
}
// IEnumerator spawnOcto()
// {
// }
// Update is called once per frame
void Update()
{
}
}