Hi! I am creating the “Laser Defender” game from the Unity 2D course. I was attempting to add some personal flare to the project by having enemies come from the top of the screen while facing sideways and shooting from the sides of the screen. However, I am unsure of how to accomplish this. Here is the script for spawning enemies:
IEnumerator SpawnEnemyWaves()
{
do
{
foreach(WaveConfigSO wave in waveConfigs)
{
currentWave = wave;
for(int i = 0; i < currentWave.GetEnemyCount(); i++)
{
Instantiate(currentWave.GetEnemyPrefab(i),
currentWave.GetStartingWayPoint().position,
Quaternion.Euler (0, 0, 180), transform);
yield return new WaitForSeconds(currentWave.GetRandomSpawnTime());
}
yield return new WaitForSeconds(timeBetweenWaves);
}
}
while(isLooping);
}
I was wondering if I could somehow attach a public float containing a “rotationPosition” onto the enemies, and then pass that variable into the Z axis parameter within the Euler? I tried multiple times but I kep coming up with an error along the lines of “rotationPosition doesn’t exist within the current context”. I was wondering if someone could help me out with this, or perhaps direct me to an appropriate place to ask. Thank you!