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);
}
}