You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HeartScript : MonoBehaviour
|
|
{
|
|
private Sprite[] HeartImages;
|
|
private List<GameObject> Hearts = new List<GameObject>();
|
|
public GameObject HeartPrefab;
|
|
public Health PL_Health;
|
|
private void Start()
|
|
{
|
|
HeartImages = Resources.LoadAll<Sprite>("Player Heart");
|
|
AddHeart();
|
|
}
|
|
private void FixedUpdate()
|
|
{
|
|
int tempHP = PL_Health.Hp;
|
|
foreach(var item in Hearts)
|
|
{
|
|
item.GetComponent<Image>().sprite = HeartImages[Math.Clamp(tempHP, 0, 13)];
|
|
tempHP -= 13;
|
|
}
|
|
}
|
|
public void AddHeart()
|
|
{
|
|
Hearts.Add(GameObject.Instantiate(HeartPrefab, this.transform));
|
|
Hearts[Hearts.Count-1].GetComponent<Image>().sprite = HeartImages[13];
|
|
Hearts[Hearts.Count-1].GetComponent<RectTransform>().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();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|