twinStick/twinStickCrawler/Assets/Scripts/Creatures/Vitals.cs

45 lines
1007 B
C#
Raw Normal View History

2024-12-24 18:58:18 +00:00
using TMPro;
2024-12-17 21:46:05 +00:00
using UnityEngine;
public class Vitals : MonoBehaviour
{
[SerializeField]
private float initHealth = 100;
2024-12-24 18:58:18 +00:00
[SerializeField]
private GameObject canvas;
[SerializeField]
private GameObject damagePrefab;
2024-12-24 13:34:15 +00:00
private float health;
public float Health
{
get
{
return health;
}
set
{
2024-12-24 18:58:18 +00:00
GameObject damageInstance = Instantiate(damagePrefab, canvas.transform);
damageInstance.transform.localPosition = Vector3.zero;
damageInstance.GetComponent<TextMeshProUGUI>().SetText(Mathf.Abs((int)value).ToString());
if (value < 0)
{
//hit
}
else
{
//heal
}
health += value;
2024-12-24 13:34:15 +00:00
}
}
2024-12-17 21:46:05 +00:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
2024-12-24 13:34:15 +00:00
health = initHealth;
2024-12-17 21:46:05 +00:00
}
}