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 = 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();
spawn = gameController.GetComponentInChildren();
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.
↧