This is from EnemySpawner.cs, but reworked to accept formations. For some reason the game is evidently reading the code, but is actually not using them somehow, and is behaving as if those values don’t exist. Also no errors appear in the console, so I don’t know what I’m doing wrong here. Help?
NOTE: Enemies DO spawn, shoot, and disappear as intended, but again they’re not spawning in the correct coordinates.
private IEnumerator SpawnAllEnemiesInWaves(WaveConfig waveConfig)
{
float yPosRandomFactor = waveConfig.GetSpawnPlaceRNG();
float yPosRandomizer = Random.Range(yPosRandomFactor, -yPosRandomFactor);
int formationCount = 0;
var formationPos = waveConfig.GetFormation()[formationCount].transform.position;
var waypointPos = waveConfig.GetWaypoints()[0].transform.position;
var spawnPoint = (Vector2)(waypointPos + formationPos);
float spawnTimer = waveConfig.GetTimeBetweenSpawns();
float spawnTimerRandomizer = waveConfig.GetTimeBetweenSpawnsRNG();
float overallSpawnTimer = Random.Range(
spawnTimer + spawnTimerRandomizer,
spawnTimer - spawnTimerRandomizer);
spawnPoint.y += yPosRandomizer;
yield return new WaitForSeconds(waveConfig.GetFloatDelay());
for (int waveEnemyCount = 0; waveEnemyCount < waveConfig.GetEnemyQuantity(); waveEnemyCount++)
{
Debug.Log(waveConfig.GetFormation()[formationCount].transform.position);
var newEnemy = Instantiate(
waveConfig.GetEnemyPrefab(),
spawnPoint,
Quaternion.identity);
Debug.Log(newEnemy.name + " spawned.");
//Debug.Log(newEnemy.GetComponent<EnemyPath>());
//Debug.Log(++waveEnemyCount);
newEnemy.GetComponent<EnemyPath>().SetWaveConfig(waveConfig);
formationCount++;
if (formationCount > waveConfig.GetFormation().Count - 1) { formationCount = 0; }
formationPos = waveConfig.GetFormation()[formationCount].transform.position;
yield return new WaitForSeconds(overallSpawnTimer);
}
}