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.
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.
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:
From then on you can just obtain a reference to the component as you would any other:
var healthBar = GetComponent<ENPCHealthBar>();
healthBar.Value -= damageValue; //Take damage healthBar.Value += healValue; //Gain health
healthBar.MaxValue = 2000;
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.