Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Sirenix.OdinInspector;
- using UnityEngine;
- using Tools;
- using Player;
- using TMPro;
- namespace UI
- {
- public class Healthbar : SerializedMonoBehaviour
- {
- [SerializeField] private TMP_Text _healthText;
- [SerializeField] private ISliderAnimation _sliderAnimation;
- [SerializeField] private IHealthy _healths;
- private void OnValidate()
- {
- _sliderAnimation.VerifyNotNull<ISliderAnimation>(nameof(_sliderAnimation));
- _healths.VerifyNotNull<IHealthy>(nameof(_healths));
- }
- private void OnEnable()
- {
- _healths.HealthChanged += OnHealthChange;
- }
- private void OnDisable()
- {
- _healths.HealthChanged -= OnHealthChange;
- }
- private void Start()
- {
- OnHealthChange(_healths.Amount);
- }
- private void OnHealthChange(float health)
- {
- _sliderAnimation.SetValue(health / _healths.MaxAmount);
- _healthText.text = health.ToString("F0");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement