33 lines
723 B
C#
33 lines
723 B
C#
using Microsoft.Unity.VisualStudio.Editor;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
[SerializeField] private int health;
|
|
[SerializeField] private int maxHealth;
|
|
[SerializeField] private GameObject healthGameObject;
|
|
|
|
public void TakeDamage(int damage)
|
|
{
|
|
if (health + damage > 0)
|
|
{
|
|
health -= damage;
|
|
UpdateGUI();
|
|
}
|
|
}
|
|
|
|
public void Heal(int healAmount)
|
|
{
|
|
if (health + healAmount <= maxHealth)
|
|
{
|
|
health += healAmount;
|
|
UpdateGUI();
|
|
}
|
|
}
|
|
|
|
private void UpdateGUI()
|
|
{
|
|
healthGameObject.GetComponent<TextMeshProUGUI>().text = health.ToString();
|
|
}
|
|
}
|