Problem rendering an image in a canvas
Good evening! i'm having a little problem with an Image inside a Canvas, my character and the other enemies have a health bar, but when there is more than 1 healthbar on the screen just one is showed. And when the char with this healthbar dies the other health bar appears. I was trying some things and when i changed the order in layer it worked, but i want to know with there is any other solutions, cuz my enemies are going to be all instantiated.
Could you post the code you're using to render the health bars? The easiest way I can think of to give every object its own health bar is to put a canvas just for that enemy in the prefab. Then when you instantiate the enemy, it instantiates the health bar with them.
Well when an enemy spawns om my Start()
i call the following method:
public void updateStatusIndicator() {
StatusIndicator statusIndicator = getStatusIndicator();
if (statusIndicator != null) {
statusIndicator.setHealth(currentHealth, maxHealth);
}
}
public void setHealth(float current, float max) {
float value = current / max;
healthBarRect.localScale = new Vector3(value, healthBarRect.localScale.y, healthBarRect.localScale.z);
healthText.text = current + "/" + max + " HP";
}
But I don't think the problem is on the code, cuz when I change the order in layer of the enemy to 1 or more the healthbar appears.