using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HeartScript : MonoBehaviour { private Sprite[] HeartImages; private List Hearts = new List(); public GameObject HeartPrefab; public Health PL_Health; private void Start() { HeartImages = Resources.LoadAll("Player Heart"); AddHeart(); } private void FixedUpdate() { int tempHP = PL_Health.Hp; foreach(var item in Hearts) { item.GetComponent().sprite = HeartImages[Math.Clamp(tempHP, 0, 13)]; tempHP -= 13; } } public void AddHeart() { Hearts.Add(GameObject.Instantiate(HeartPrefab, this.transform)); Hearts[Hearts.Count-1].GetComponent().sprite = HeartImages[13]; Hearts[Hearts.Count-1].GetComponent().anchoredPosition3D = new Vector3(5 + ((Hearts.Count-1) * 53), -5, 0); //.HeartStrength += 13; } public void die() { foreach(var item in Hearts) { GameObject.Destroy(item); } Hearts.Clear(); } }