I’ve been looking into having a healthbar on enemy characters for a while and didn’t really find a good or working solution. Using a slider for the player is fine, but if you want to have it on your enemy it gets messy with it requiring a canvas.
After trying different things it seems it’s possible to achieve it in an easy way. On my enemy character I’ve added an empty child game object. Added a spriterenderer, that has a sprite shaped a s a rectangle. I’ve set the scale of the rectangles X to 1.2 (this value represents the enemy’s health which is set as 120). Then in my update script I have simply this:
The only disadvantage for now is that while the healthbar does decrease, it decreases towards the center.
Hopefully this may be helpful for someone looking to implement something similar. I’m sure there may be a better way to achieve this, and if so, I’d love to hear it!