UnityProjekt/Assets/Scripts/HUDManager.cs
2020-12-06 18:33:36 +01:00

25 lines
No EOL
650 B
C#

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;
}
}
}