Quelques trucs pour structuer

This commit is contained in:
Crizomb 2024-12-21 18:35:07 +01:00
parent af46b49095
commit 1165e50bb5
15 changed files with 245 additions and 2 deletions

View file

@ -0,0 +1,38 @@
using UnityEngine;
public class HealthHandler : MonoBehaviour
{
[SerializeField] private float maxHealth;
[SerializeField] private float currentHealth;
[SerializeField] private float armor;
public void TakeDamage(float damage)
{
Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal");
currentHealth -= Mathf.Max(0, damage-armor);
}
public void Heal(float value)
{
Debug.Assert(value >= 0, "value can't be less than zero");
currentHealth = Mathf.Min(currentHealth + value, maxHealth);
}
public float GetArmor()
{
return armor;
}
public void EquipArmor(float armorBoost)
{
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use UnEquipArmor instead");
armor += armorBoost;
}
public void UnEquipArmor(float armorBoost)
{
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use EquipArmor instead");
armor -= armorBoost;
}
}