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 int HeartStrength = 0; private void Start() { HeartImages = Resources.LoadAll("Player Heart"); AddHeart(); } private void FixedUpdate() { int tempHP = HeartStrength; 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 += 14; } }