Masked Health Bar

start-temp-ui

So here’s where my implementation differs from Ben’s:

  • Created another PSD to use as a mask for the health bar
    • Mask image is an image component on health bar mask
  • Added Mask component to health bar mask
    • This let’s Unity do some magic that takes takes the alpha values from the GameObject with the Mask component and applies it to the Image component in the Child gameobjects
  • Made the health bar GameObject a child of health bar mask
  • Duplicated the whole prefab and swapped out the background bar with a different color to make an energy meter.

The energy meter and the health meter are both technically still health bars, because they both use the Player Health script. I was thinking about refactoring the health script to be more of a UI controller and using it to update both Health and Energy, but I might also wait until Section 3 when that actually gets implemented.

Of course, I could always just create a new git branch and experiment. Not like I couldn’t go back. :stuck_out_tongue:

1 Like

So here’s what I did:

  1. Created an enum to define the stat that the energy bar represents (Health, Energy) and serialized it in the Inspector so you get a nice dropdown.

  2. Switch on the enum selected in the inspector to determine what getter to call from Player

  3. Copypasta’d the HealthAsPercentage getter method to create an EnergyAsPercentage getter.

I also turned the serialized floats in the inspector into range sliders for now. When I implement the stats themselves, I will probably refactor them out of the inspector since HP and EP will be derived values.

Privacy & Terms