Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created December 29, 2016 06:41
Show Gist options
  • Save unity3dcollege/c07172a75f7654fcef8bc3bc851bc990 to your computer and use it in GitHub Desktop.
Save unity3dcollege/c07172a75f7654fcef8bc3bc851bc990 to your computer and use it in GitHub Desktop.
Updated HPBar.cs
using UnityEngine;
using UnityEngine.UI;
public class HPBar : MonoBehaviour
{
private Slider slider;
private void Start()
{
slider = GetComponentInChildren<Slider>();
GetComponentInParent<Health>().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