Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created December 30, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unity3dcollege/fe079cbe1f39ea7a3e7dc057143e0915 to your computer and use it in GitHub Desktop.
Save unity3dcollege/fe079cbe1f39ea7a3e7dc057143e0915 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class HPBar : MonoBehaviour
{
private Slider slider;
private void Start()
{
slider = GetComponentInChildren<Slider>();
GetComponentInParent<IHealth>().OnHPPctChanged += HandleHPPctChanged;
}
private void HandleHPPctChanged(float pct)
{
slider.value = pct;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment