Created
December 30, 2016 20:14
-
-
Save unity3dcollege/fe079cbe1f39ea7a3e7dc057143e0915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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