Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Events;
- public class Hero : MonoBehaviour
- {
- [SerializeField] private UnityEvent _healthChanged;
- [SerializeField] private float _value;
- [SerializeField] private float _maxHealth;
- [SerializeField] private float _health;
- public event UnityAction HealthChanged
- {
- add => _healthChanged.AddListener(value);
- remove => _healthChanged.RemoveListener(value);
- }
- public float Health => _health;
- public float MaxHealth => _maxHealth;
- public void Heal()
- {
- _health = Mathf.Clamp(_health + _value,0,_maxHealth);
- _healthChanged?.Invoke();
- }
- public void Damage()
- {
- _health = Mathf.Clamp(_health - _value,0,_maxHealth);
- _healthChanged?.Invoke();
- }
- }
Add Comment
Please, Sign In to add comment