initial weapons
This commit is contained in:
1 parent
b87010d2e5
commit
afcd8761e6
66 files changed
+6388
-49
No files matched your search
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Code.Gameplay.Core;
|
||||
|
||||
namespace Code.Gameplay.Character.Stats
|
||||
{
|
||||
public class HealthSystem : MonoBehaviour, IDamageable
|
||||
{
|
||||
[SerializeField] private float maxHealth = 100f;
|
||||
[SerializeField] private float currentHealth;
|
||||
|
||||
public event Action<float, float> OnHealthChanged;
|
||||
public event Action OnDied;
|
||||
|
||||
public float CurrentHealth => currentHealth;
|
||||
public float MaxHealth => maxHealth;
|
||||
public float HealthPercentage => currentHealth / maxHealth;
|
||||
public bool IsAlive => currentHealth > 0;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
if (!IsAlive) return;
|
||||
|
||||
currentHealth = Mathf.Max(0, currentHealth - damage);
|
||||
OnHealthChanged?.Invoke(currentHealth, maxHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(float amount)
|
||||
{
|
||||
if (!IsAlive) return;
|
||||
|
||||
currentHealth = Mathf.Min(maxHealth, currentHealth + amount);
|
||||
OnHealthChanged?.Invoke(currentHealth, maxHealth);
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
OnDied?.Invoke();
|
||||
}
|
||||
|
||||
public Transform GetTransform() => transform;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user