diff options
Diffstat (limited to 'Assets/Scripts/UI.cs')
-rw-r--r-- | Assets/Scripts/UI.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Assets/Scripts/UI.cs b/Assets/Scripts/UI.cs new file mode 100644 index 0000000..0c0802e --- /dev/null +++ b/Assets/Scripts/UI.cs @@ -0,0 +1,43 @@ +using MontanaJohns.Actors; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class UI : MonoBehaviour +{ + [SerializeField] private int heartCount; + [SerializeField] private Image[] hearts; + [SerializeField] private Sprite heartSprite; + + public int health; + + private void Start() + { + for (int i = 0; i < hearts.Length; i++) + { + if (i < heartCount) + hearts[i].enabled = true; + else + hearts[i].enabled = false; + } + } + + private void Update() + { + health = gameObject.GetComponent<Actor>().health; + for(int i = 0; i < heartCount; i++) + { + /* Can be used to have two sprites, one empty/one full/half full, etc. + if (i < health) + hearts[i].sprite = heartSprite; + else + hearts[i].sprite = heartSprite2; + */ + if (i < health) + hearts[i].enabled = true; + else + hearts[i].enabled = false; + } + } +} |