Sprite Healthbars

Primary info about Sprite Healthbars

Sprite Healthbars is good thing to use in 2D games, because they work faster than Ui Healthbars. Also can be used in 3D games, but visual quality not so good as Ui Healthbars.

Sprite Healthbars have not so much features, but it should be enough for 2D games.

You can check ExampleSpriteScene scene to see how it works.

To setup this type of healthbars, you do not need any canvas, just create an empty scene object and add SpriteHealthbars component to it.

Next, setup its parameters as you want. Main parameter you need to setup is Healthbar Template prefab. To start, you can use default one from asset resources, named SpritePrefab.

To add healthbar to your game character, you need to do these things:

  1. Make your class implement IHealthed interface and all its methods. It is very simple, you can check asset Damageable script as example.

  2. Call SpriteHealthbars.AddHealthbar method at your character script in the Start method.

Finally, it can look like this (there can be also placed any other your code, of course):

using InsaneSystems.HealthbarsKit;

class YourCharacter : MonoBehaviour, IHealthed
{
  void Start()
  {
    SpriteHealthbars.AddHealthbar(this);
  }
}

Custom sprite healthbar visual

If you want make your own sprite healthbar, you need to set its Fill Sprite pivot to the Left Center.

../_images/sprite-setup.png

Next, you need to setup prefab, it should have at least Fill sprite which will be handled by asset. Also you can add decorative background, etc:

Note

Since your image pivot point is now on the left side, you need set its X coordinate to a half of its size with negative sign.

You also can edit its size manually, so don’t forget about correcting X coordinate in this case.

../_images/sprite-prefab-setup.png

Note

Its Draw Mode will be automatically set to the Sliced by asset.

Finally, you need to drag’n’drop it to the SpriteHealthbars component on your scene.

../_images/sprite-healthbars-prefab-setup.png