Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created December 30, 2016 20:12
Show Gist options
  • Save unity3dcollege/35fde8c830c8798853ce43b5cae1f077 to your computer and use it in GitHub Desktop.
Save unity3dcollege/35fde8c830c8798853ce43b5cae1f077 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