How does this work ?.
In the EnemySpawner ( function SpawnAllEnemiesInWave.) we create an instance of the enemy.
var newEnemy = Instantiate(waveConfig.GetEnemyPrefab(),
waveConfig.GetWayPoints()[0].transform.position,
Quaternion.identity);
Afterwards we setup waveConfig for the enemy
newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);
But at first , when we first create the instance of the enemy, it does not know what the waveConfig is. It first know it when we set it up in the second line.
I can see that the start of EnemyPathing(the code below), when it create the instance of the Enemy, use waveConfig. But it is not set there at this time. Why does this work and not resulting in a error ?
private void Start()
{
waypoints = waveConfig.GetWayPoints();
transform.position = waypoints[waypointIndex].transform.position;
}
Mayby a constructor could be used here. Eg public void Start(WaveConfig waveConfig)