[UNITY 2D] Can I create a spawner that spawns another enemy after its death using IF statements?

Will this work or would i need something else? I am taking a udemy course and the TA said that i can not use IF statements because it’s not a number and I am dealing with gameobjects.

ALSO Will this work if i destroythe gameobject after a certain amount of time? at the moment my player is able to attack enemies.

    public GameObjecct Enemy;
    public float spawnTime;
    private float timeReset;
    
    private void Start ()
    {
          timeReset = spawnTime;
    }
    
    void Update()
    {
         spawnTime -= 2 * Time.detalTime;
    
         if (enemyHealth <= 0)
       {
            Instantiate (Enemy, transform.position, Quaternion.identity);
            timeReset = 0;
       }
    }

It depends what you are doing with the enemy GameObjects once they hit zero health. If you are destroying them just as an if statement to count the number of enemies and only spawn if you have less than the maximum.

     public GameObjecct Enemy;
     public float spawnTime;
     private float timeReset;
     private int MaxEnemies=10;
    private int EnemyCount;

     private void Start ()
     {
           timeReset = spawnTime;
     }
     
     void Update()
     {
          spawnTime -= 2 * Time.detalTime;
      
          if (enemyHealth <= 0 && EnemyCount<MaxEnemies)
        {
             Instantiate (Enemy, transform.position, Quaternion.identity);
             timeReset = 0;
             EnemyCount+=1;
        }
     }
 
// In your code that destroys the enemies
EnemyCount-=1;

If you don’t destroy them, you’ll want to just adjust the MaxEnemies count at the point they hit zero health instead. Make sure it’s a trigger though, so they don’t continually adjust the count whilst they remain at 0.

Try this:

public GameObject EnemyPrefab;
public GameObject CurrentEnemy;

void Update() {

    if (!CurrentEnemy) {
        CurrentEnemy = Instantiate(EnemyPrefab, transform.position, Quaternion.identity);
    }
}

It will spawn an enemy as soon as the one it spawned is destroyed.

I am taking a udemy course and the TA said that i can not use IF statements because it’s not a number and I am dealing with gameobjects.

If your TA said this, they are wrong!