Question by
MrSlitherGamer_YT · Jun 13, 2020 at 12:55 AM ·
counting
How do I count the amount of enemies in my game?
The game I intend to make is a game about depression, if 15 depression squares (enemies) are on the screen then you become depressed, and lose the game. How can I count the amount of enemies in the scene and make the equation (health) - (the amount of enemies) = new health? Here's my code now.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class HealthBarScript : MonoBehaviour { public Slider slider;
public void SetMaxHealth (int health)
{
slider.maxValue = health;
slider.value = health;
}
public void SetHealth (int health)
{
slider.value = health;
}
}
Comment
Answer by Galactic_CakeYT · Jun 13, 2020 at 06:27 AM
Maybe you can try to store your enemies in an array, that is only used for keeping track of the number of enemies