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
1008 B

5 years ago
  1. using Unity.FPS.Game;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Unity.FPS.UI
  5. {
  6. public class WorldspaceHealthBar : MonoBehaviour
  7. {
  8. [Tooltip("Health component to track")] public Health Health;
  9. [Tooltip("Image component displaying health left")]
  10. public Image HealthBarImage;
  11. [Tooltip("The floating healthbar pivot transform")]
  12. public Transform HealthBarPivot;
  13. [Tooltip("Whether the health bar is visible when at full health or not")]
  14. public bool HideFullHealthBar = true;
  15. void Update()
  16. {
  17. // update health bar value
  18. HealthBarImage.fillAmount = Health.CurrentHealth / Health.MaxHealth;
  19. // rotate health bar to face the camera/player
  20. HealthBarPivot.LookAt(Camera.main.transform.position);
  21. // hide health bar if needed
  22. if (HideFullHealthBar)
  23. HealthBarPivot.gameObject.SetActive(HealthBarImage.fillAmount != 1);
  24. }
  25. }
  26. }