Enemy + NPC Health Bars

(Unity Asset)

Check out the demo video

ENPCHealthBars was developed to be a quick and easy solution to add health bars to enemies, NPCs, or any object at all in your game.

The ENPCHealthBar Inspector

Adding the ENPCHealthBar component to any object in the Unity Editor will present you with the following controls in the inspector. There you can customize how the health bar will look, it’s position, and the maximum health value assigned to the bar.

The Code

It’s very simple and intuitive to work with ENPCHealthBars from your C# code. First, add the following namespace directive to the top of your C# script:

using SnazzlebotTools.ENPCHealthBars;

From then on you can just obtain a reference to the component as you would any other:

var healthBar = GetComponent<ENPCHealthBar>();
ENPCHealthBar.Value – To reduce or increase the health bar, simply modify the component’s ‘Value’ property.
healthBar.Value -= damageValue; //Take damage healthBar.Value += healValue; //Gain health
ENPCHealthBar.MaxValue – To specify the healthbar’s maximum value (the health value of the enemy/NPC when full) use the component’s ‘MaxValue’ property.
healthBar.MaxValue = 2000;

Runtime Creation

You can also add healthbars to any objects during the runtime of your game, for dynamically created enemies or NPCs for example.
Simply add the component to the relevant object, and code against it as you would normally.

newEnemyGameObject.AddComponent<ENPCHealthBar>();
Get it on the Unity Asset Store
Comments, Requests & Bug Reports