Implemented turn passing and taking damage from it.

This commit is contained in:
Max Dodd 2025-01-23 10:22:22 +01:00
parent 31917ba415
commit ede5ef1533
6 changed files with 572 additions and 15 deletions

View file

@ -0,0 +1,39 @@
using System;
using Microsoft.Unity.VisualStudio.Editor;
using TMPro;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField] private int maxHealth;
[SerializeField] private GameObject healthGameObject;
private int _healthIndex = 0;
private readonly int[] _healthBar = {0, 0, -1, -2, -4, -6, -9, -12, -16, -20};
private void Start() {
UpdateGUI();
}
public void TakeDamage(int damage)
{
if (_healthIndex + damage < _healthBar.Length)
{
_healthIndex += damage;
UpdateGUI();
}
}
public void Heal(int healAmount)
{
if (_healthIndex - healAmount >= 0)
{
_healthIndex -= healAmount;
UpdateGUI();
}
}
private void UpdateGUI()
{
healthGameObject.GetComponent<TextMeshProUGUI>().text = _healthBar[_healthIndex].ToString();
}
}