2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

5 years ago
  1. using Unity.FPS.Game;
  2. using Unity.FPS.Gameplay;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Unity.FPS.UI
  6. {
  7. public class PlayerHealthBar : MonoBehaviour
  8. {
  9. [Tooltip("Image component dispplaying current health")]
  10. public Image HealthFillImage;
  11. Health m_PlayerHealth;
  12. void Start()
  13. {
  14. PlayerCharacterController playerCharacterController =
  15. GameObject.FindObjectOfType<PlayerCharacterController>();
  16. DebugUtility.HandleErrorIfNullFindObject<PlayerCharacterController, PlayerHealthBar>(
  17. playerCharacterController, this);
  18. m_PlayerHealth = playerCharacterController.GetComponent<Health>();
  19. DebugUtility.HandleErrorIfNullGetComponent<Health, PlayerHealthBar>(m_PlayerHealth, this,
  20. playerCharacterController.gameObject);
  21. }
  22. void Update()
  23. {
  24. // update health bar value
  25. HealthFillImage.fillAmount = m_PlayerHealth.CurrentHealth / m_PlayerHealth.MaxHealth;
  26. }
  27. }
  28. }