Hey guys so in my enemy spawner script I set the max number of enemies to 10 but it just spawns 10 enemies and then stops. I noticed that in the inspector the enemy count did not decrease as enemies were destroyed so that’s probably why. How do I get the count to decrease?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy_Spawn_script : MonoBehaviour
{
public GameObject theEnemy;
public float xpos;
public float ypos;
public int enemyCount;
void Start()
{
StartCoroutine(EnemyDrop());
}
IEnumerator EnemyDrop()
{
while (enemyCount< 10)
{
xpos = Random.Range(1, 5);
ypos = Random.Range(4, 8);
Instantiate(theEnemy, new Vector3(xpos, ypos, 0), Quaternion.identity);
yield return new WaitForSeconds(1);
enemyCount += 1;
}
}
}