UnityProjekt/Assets/Scripts/HUDManager.cs

25 lines
650 B
C#
Raw Normal View History

2020-12-06 17:33:36 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HUDManager : MonoBehaviour
{
public Image[] hearts;
public Sprite heartFull, heartHalf, heartEmpty;
public void UpdateHealth(float health)
{
int hpph = 100 / hearts.Length;
for (int i = 0; i < hearts.Length; i++)
{
if (health >= hpph * i + 3 * hpph / 4)
hearts[i].sprite = heartFull;
else if (health < hpph * i + hpph / 4)
hearts[i].sprite = heartEmpty;
else
hearts[i].sprite = heartHalf;
}
}
}