I have a working script where at the start my set number of max enemies will Spawn, and upon killing them the next wave starts and spawns the same number of enemies. However when I put in multiple spawners with this script, the enemies only spawn out of one spawner. How can I use this wave spawning system across multiple spawners?
This is my current Wave Spawning Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawnWaveBased : MonoBehaviour {
public int totalWaves = 5;
private int numWaves = 0;
private bool waveSpawn;
public bool Spawn = true;
public SpawnTypes spawnType = SpawnTypes.Wave;
public int totalEnemy = 10;
public static int numEnemy;
public GameObject Enemy;
void Start () {
}
void Update () {
Debug.Log(waveSpawn);
GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy");
numEnemy = enemies.Length;
if(Spawn)
{
if (spawnType == SpawnTypes.Wave)
{
if(numWaves < totalWaves + 1)
{
if (numEnemy == 0)
{
// enables the wave spawner
waveSpawn = true;
//increase the number of waves
numWaves++;
}
if (waveSpawn)
{
//spawns an enemy
spawnEnemy();
}
if(numEnemy >= totalEnemy)
{
// disables the wave spawner
waveSpawn = false;
}
}
}
}
}
private void spawnEnemy()
{
if (waveSpawn == true) {
Instantiate (Enemy, gameObject.transform.position, Quaternion.identity);
}
}
public enum SpawnTypes
{
Wave
}
}