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
- Mask image is an image component on
- 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 ofhealth 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.