Could it be that you asked the same question on Udemy, too? If so, I’ve replied to you there. I’m pasting my answer here.
Are you referring to this method?
private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig)
{
for (int enemyCount = 0; enemyCount < waveConfig.GetNumberOfEnemies(); enemyCount++)
{
var newEnemy = Instantiate(
waveConfig.GetEnemyPrefab(),
waveConfig.GetWaypoints()[0].transform.position,
Quaternion.identity);
newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);
yield return new WaitForSeconds(waveConfig.GetTimeBetweenSpawns());
}
}
If so, we instantiate all our enemies at the position of the first waypoint in our List. The first element in a List or an array is at index 0.
If you instantiate the enemy at index 1, 2 or 3 and the enemy appears at the same position as index 0, that’s very likely due to the EnemyPathing object. Our waypointIndex value is initialised with 0. And in Start, we assign the position of the first element to the transform.position.
int waypointIndex = 0;
void Start ()
{
waypoints = waveConfig.GetWaypoints();
transform.position = waypoints[waypointIndex].transform.position;
}
This means that we could instantiate our enemy at other positions and will always get the same result. For example:
var newEnemy = Instantiate(
waveConfig.GetEnemyPrefab(),
new Vector3(1000f, 1000f, 1000f),
Quaternion.identity);