Health Bar
A simple health bar which uses a PlayerObject to sync and persist players' health amounts.
Visit the HealthBar Persistence Example World to try it for yourself!
Using the Example
- Open the HealthBar_ExampleScene.
- Run it in the editor or Build & Test.
- Walk over to the red 'lava' and stand in it.
- Look directly up to see your health bar, which will be shrinking as you continue to stand in the lava.
- Exit the lava, take note of your health bar, and rejoin the world.
- Your health will be restored to its previous level. Note that if you let your health bar run out entirely, you will respawn and your health will be restored to its full amount.
Importing the Example
Follow the steps below to add this example to your Unity project:
- Open the Example Central Window from the window from the Unity Editor Menu under "VRChat SDK > 🏠 Example Central"
- Find this prefab in the list or search for it by title (same as the title of this page).
- Press the "Import" button to import the Unitypackage into your project.
Technical Breakdown
The lava stores a reference to the local player's health bar. Upon entering the trigger, it will start damaging the player through the health bar's TakeDamage
function (which should only be called on the local client).
Inspector Parameters
You can customize the prefabs by changing their parameters:
HealthBar
float
MaxHealth - The player's maximum health.Vector3
Offset Above Head - The distance of the health bar above the player's head.Slider
Health Bar Slider - The UI slider that shows the player's health.
Lava
float
Damage per second - The damage per second that the lava deals to players touching it.
Changelog
- 0.0.1 - Initial Version
- 0.0.2 - Added in-world UI, thumbnail, published world