Simple Health System
Simple Health System provides a robust health management solution with damage, healing, and death mechanics. Features include invulnerability toggles, customizable UnityEvents for game logic integration, and flexible UI display options—bar sliders, numeric formats (raw, percentage, or "current/max"), and custom layouts. Easily subscribe to health events through scripts or the inspector for seamless gameplay implementation.
com.mateojimenez.healthsystem Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/healthsystem.git README Markdown
Copy this to your project's README.md
## Installation
Add **Simple Health System** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/healthsystem.git
```
[](https://www.pkglnk.dev/pkg/healthsystem)Dependencies (1)
README
Simple Health Package
How To Use
Dealing Damage
To deal damage call the Damage(int amount) function. When damage is taken all events in the OnDamage UnityEvent will be invoked and if health is <= 0 then OnDeath will be invoked aswell.
[!IMPORTANT] OnDeath is invoked AFTER OnDamage and not instead of.
There is also an option to negate all damage via bool BeInvulnerable(bool value).
Implimentation in Health.cs/Damage(int amount)
Healing
To heal call the Heal(int amount) function. This function will also invoke all events in the OnHealth UnityEvent.
Implimentation in Health.cs/Heal(int amount)
Subscribing / Unsubscribing From Events
If you would like to subscribe to the events through scripts you can call SubscribeTo...(UnityAction action) followed by the name of the corresponding Unity Event. Ex: SubscribeToOnDeath(UnityAction action). To unsubscribe is the same process but instead you call UnsubscribeFrom...(UnityAction action) with the UnityAction you wish to remove from the Event.
Health Displayer
Prerequisites
A Health script is required to be on the same object as the HealthDisplayer.
If one is not already on it then one will be created for you due to the effect of [RequireComponent(typeof(Health))]
Displaying As A Bar
Prerequisites
A reference to a Slider is required
Displaying As A Number
Prerequisites
A TextMeshProUGUI is required. While displaying as a number there are several formats to chose from which go as follows.
Number Display Options
| Type | Result |
|---|---|
| Out Of | 50/100 |
| Percentage | 50% |
| Raw Number | 50 |
| Custom | This splits the max and current health values into two separate TextMeshProUGUI objects allowing for the user to manipulate placement and text styles however they please. |
Additional Reading
https://docs.unity3d.com/Packages/com.unity.textmeshpro@4.0/api/TMPro.TextMeshProUGUI.html
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/UIElements.Slider.html
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Events.UnityAction.html
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/RequireComponent.html
No comments yet. Be the first!