Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Tools;
- using UnityEngine;
- using UnityEngine.Events;
- namespace Player
- {
- public class Health : MonoBehaviour, IHealthy
- {
- [SerializeField] private float _amount;
- [SerializeField] private float _maxAmount = 100f;
- public event UnityAction<float> HealthChanged;
- public float Amount => _amount;
- public float MaxAmount => _maxAmount;
- public void Cure(float cure)
- {
- cure.VerifyPositive(nameof(cure));
- _amount += cure;
- _amount = Mathf.Min(_amount, _maxAmount);
- HealthChanged?.Invoke(_amount);
- }
- public void Damage(float damage)
- {
- damage.VerifyPositive(nameof(damage));
- _amount -= damage;
- _amount = Mathf.Max(_amount, 0f);
- HealthChanged?.Invoke(_amount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement