Make enemies spawn everytime that the previous enemy health reaches to 0

Hey, I’m trying to make enemies continues to spawn after the previous enemy health reaches to 0.

This scritp works fine but only to spawn the enemy once, but once the second enemy health reaches to 0 the next one doesn’t spawn.

This is my spawner script right now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class SpawnManager : MonoBehaviour
{
    // Enemies Prefabs objects
    public GameObject enemyT1;
    public GameObject enemyT2;
    public GameObject enemyT3;
    public GameObject enemyBoss;

    //Enemy stats variables
    public float enemyT1Health = 100;
    public float enemyT2Health = 200;
    public float enemyT3Health = 300;
    public float enemyBossHealth = 1000;
    public float enemySpawned = 0;

    //Player stats variables
    public float playerDamage = 10;
    public float levelUp = 10;

    // Stage;
    int stageNumber = 1;



    // Start is called before the first frame update
    void Start()
    {
        Stage();
    }

    // Update is called once per frame
    void Update()
    {
        if (enemyT1Health == 0)
        {
            Destroy(gameObject);
            enemyT1Health = 100 + (20 * stageNumber);
            stageNumber++;
            enemySpawned++;
            Debug.Log("Now you are on Stage: " + stageNumber + " and the enemy HP is: " + enemyT1Health);

            Stage();
        }

    }

    void Stage() 
    {
        Vector3 spawnPos = new Vector3(0, 0, 1);
        Quaternion rotationPos = (transform.rotation = Quaternion.Euler(90f, 0f, 0f));

        Debug.Log("This is the: " + stageNumber + " time that this script is been called and we have" + "0");

        if(stageNumber > 0 && stageNumber < 4 && GameObject.FindGameObjectsWithTag("Enemy").Length == enemySpawned)
        {
            Instantiate(enemyT1, spawnPos, rotationPos);
        }

    }

    private void OnMouseDown()
    {
        enemyT1Health = enemyT1Health - playerDamage;
        Debug.Log("Enemy Current Health " + enemyT1Health);
    }
}

There are a couple of things I would change were you to keep the code like this but you should really think of an alternative way of coding this. Instead of destroying your game object and instantiating another, just reset the values of the first one (position, rotation, health, stagenumber etc).

It may not make a big difference in a game like this but reusing game objects instead of destroying and instantiating is called Object Pooling and it’s an important of game performance. If you haven’t heard of the term Garbage Collection, it’s the process of tidying up after you destroy something or no longer need an array that you created. Garbage Collection can cause glitches in games and, if you can design to eliminate Garbage Collection, all the better.

I think a couple of minutes thinking about how to restructure your code would lead to a much neater, a better performing and bug free script.

if (enemyT1Health == 0)
{
    Rebirth()
}