- Home /
 
My wave system isn't working
This is my wave system .
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Spawner : MonoBehaviour {
 private int waveNumber = 0;
 public int enemySpawnAmount = 0;
 public int enemiesKilled = 0;
 public GameObject[] spawners;
 public GameObject enemy;
 private void Start()
 {
     //Change the number to the amount of spawners you have
     spawners = new GameObject[10];
     for (int i = 0; i < spawners.Length; i++)
     {
         spawners[i] = transform.GetChild(i).gameObject;
     }
     StartWave();
 }
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.T))
     {
         SpawnEnemy();
     }
     if(enemiesKilled >= enemySpawnAmount)
     {
         NextWave();
     }
 }
 private void SpawnEnemy()
 {
     int spawnerID = Random.Range(0, spawners.Length);
     Instantiate(enemy, spawners[spawnerID].transform.position, spawners[spawnerID].transform.rotation);
 }
 public void StartWave()
 {
     waveNumber = 1;
     enemySpawnAmount = 1;
     enemiesKilled = 0;
     for(int i = 0; i <enemySpawnAmount; i++)
     {
         SpawnEnemy();
     }
 }
 public void NextWave()
 {
     waveNumber++;
     enemySpawnAmount += 2;
     enemiesKilled = 0;
     for (int i = 0; i < enemySpawnAmount; i++)
     {
         SpawnEnemy();
     }
 }
 
               }. This is my enemy health system
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CharactorStats : MonoBehaviour {
 public int currHealth;
 public int maxHealth;
 public int currStamina;
 public int maxStamina;
 public bool isDead = false;
 public void CheckHealth()
 {
     if (currHealth >= maxHealth)
     {
         currHealth = maxHealth;
     }
     if(currHealth <= 0)
     {
         currHealth = 0;
         isDead = true;
         Die();
         
     }
 }
 public void CheckStamina()
 {
     if(currStamina >= maxStamina)
     {
         currStamina = maxStamina;
     }
     if(currStamina <= 0)
     {
         currStamina = 0;
     }
 }
 public virtual void Die()
 {
     
 }
 
               }
And this is my enemy death system
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnemyStats : CharactorStats {
 private float scoreAddAmount = 10;
 public Transform enemy;
 GameController gameController;
 Spawner spawn;
 private void Start()
 {
     gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
     spawn = gameController.GetComponentInChildren<Spawner>();
     maxHealth = 100;
     currHealth = maxHealth;
     currStamina = maxStamina;
 }
   
 private void Update()
 {
     CheckHealth();
  
 }
 private void OnCollisionEnter(Collision collisison)
 {
     if (collisison.collider.CompareTag("Player Potato"))
     {
     
         maxHealth = 0;
         gameController.AddScore(scoreAddAmount);
         
     }
 }
 
 public override void Die()
 {
     spawn.enemiesKilled++;
     Destroy(gameObject);
 }
 
 
               }
And if I put the Destroy(gameObject) before the spawn.enemiesKilled++ the enemy will die, but if it's the other way around it won't destroy the enemy.
Your answer
 
             Follow this Question
Related Questions
simple waypoint system enemy wave spawner 1 Answer
Random enemy spawning without using a radius? 1 Answer
Why doesn't my spawning code work? 2 Answers
how to kill an emeny? 1 Answer
Photon Spawn on server, not client 0 Answers