aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/UI.cs
blob: 0c0802ea6d089d80d4125ff1c8a632e297f64193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
        }
    }
}