I’m actually so confused-- Unity is calling a nullref on my Laser Defender StartCoroutine(). I’ve scoured the internet for a solution, but the GameObject the script is on hasn’t been destroyed, so I really don’t know what’s going on. Here’s my code, could someone please help me find the error? I’d really appreciate it. Thanks!
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
WaveConfigSO currentWave;
List waveSOs;
[SerializeField]bool isLooping = true;
[SerializeField] Waveset_SO currentWaveset;
void Start()
{
StartCoroutine(WaveEnemies());
waveSOs = currentWaveset.GetCurrentWaveset();
}
public WaveConfigSO GetCurrentWave()
{
return currentWave;
}
IEnumerator WaveEnemies()
{
do
{
foreach (WaveConfigSO wave in waveSOs)
{
currentWave = wave;
for (int j = 0; j < currentWave.GetEnemyCount(); j++)
{
Instantiate(currentWave.GetEnemyPrefab(j), currentWave.GetFirstPoint().position, Quaternion.identity, transform);
yield return new WaitForSeconds(currentWave.GetRandomSpawnTime());
}
yield return new WaitForSeconds(currentWaveset.GetTimeBetweenWaves());
}
}
while (isLooping);
}
}