Hi,
I find your way complex to make Health bar.
I made an Unity package, if you want it, just contact me since I cannot put it here yet.
Here how I did it.
I made an UI Image (background) red and his child is an UI Image green. And I take HealthAsPercentage as x scale. It’s really simple and I think it’s better than Ben’s way to do it in that video.
Unity :
Code :
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(RawImage))]
public class PlayerHealthBar : MonoBehaviour
{
Player player;
// Use this for initialization void Start() { player = FindObjectOfType<Player>(); }
// Update is called once per frame void Update() { transform.localScale = new Vector3(player.HealthAsPercentage,1,1); }
}