PlayerVitalsGUI.cs 708 B

12345678910111213141516171819202122232425262728293031323334
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace HQFPSWeapons.UserInterface
  4. {
  5. public class PlayerVitalsGUI : HUD_DisplayerBehaviour
  6. {
  7. [SerializeField]
  8. private Image m_HealthBar = null;
  9. [SerializeField]
  10. private Image m_StaminaBar = null;
  11. public override void OnPostAttachment()
  12. {
  13. Player.Health.AddChangeListener(OnChanged_Health);
  14. Player.Stamina.AddChangeListener(OnChanged_Stamina);
  15. OnChanged_Health(Player.Health.Get());
  16. OnChanged_Stamina(Player.Stamina.Get());
  17. }
  18. private void OnChanged_Health(float health)
  19. {
  20. m_HealthBar.fillAmount = health / 100f;
  21. }
  22. private void OnChanged_Stamina(float stamina)
  23. {
  24. m_StaminaBar.fillAmount = stamina / 100f;
  25. }
  26. }
  27. }