- Home /
Health bar system is not working on multiple enemies on the scene.
My enemy health bar is not working whenever I tried to add multiple enemies to my scene. Only one slider. Or if I shoot my default enemy to kill its health bar decreases also other enemies' health bar decreases as well.
[1]: /storage/temp/179467-1.png
Answer by peacemakers1980 · Apr 19, 2021 at 10:32 PM
Each 'Slider' as with each variable needs its own instance. So if your running so 100 enemies at a time, you will need it to track 100 sets of the variables and 100 sliders, one for each of them. You can use for example a Array to store them all then use a for each loop on it to update each one at a time. Also running it in the Update loop might be a issue with performance depending on just how many it needs to look at and update threw. You made a class for it, so just create a instance array of that class elsewhere to manage it as needed, then 1 update loop to show sliders. Create an array with the new command for how ever large you plan it on being, say public class enemyHealthManager { .... your class stuff }
public enemyHealthManager[] myEnemyHealth = new enemyHealthManager[100];
Your answer
Follow this Question
Related Questions
Healthbar is over play dead Animation 1 Answer
Enemy HealthBar Problems 2 Answers
How to make my health decrease? 1 Answer
Health Bars in 2D Game 1 Answer
Healthbar problem 1 Answer