Hi Ive been working on this 2D plants vs zombies style game and I’ve tried to design a wave spawner for it.
there is an array of waves that you can customize each one of, and you can also customize each praticular enemy spawn of each wave by a SpawnBlueprint that i made for it, that only contains the prefab to spawn and time after spawning it.
there is also a wave blueprint that contains an array of SpawnBlueprints and time After spawning the wave.
each enemySpawner is attached to a lane in my game, so you’re able to spawn the wave on different lanes.
There is the enemySpawner code, I’ll be glad for some suggestions.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour {
public WaveBlueprint[] waves;
void Start(){
SpawnWaves ();
}
IEnumerator SpawnWaves(){
for (int i = 0; i < waves.Length; i++) {
foreach (SpawnBlueprint blueprint in waves*.spawns) {*
-
SpawnEnemy (blueprint);*
-
//Time after spawning 1 enemy.*
-
yield return new WaitForSeconds (blueprint.timeBetweenSpawns);*
-
}*
-
//Time after spawning 1 wave.*
_ yield return new WaitForSeconds (waves .timeAfterWave);_
* }*
* }*
* void SpawnEnemy(SpawnBlueprint blueprint){*
* Instantiate (blueprint.prefab, transform.position, Quaternion.identity);*
* }*
}