HealthBar.cs 653 B

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class HealthBar : MonoBehaviour
  4. {
  5. public PlayerController playerController;
  6. public Slider healthBar;
  7. public float maxHealth;
  8. private void Start()
  9. {
  10. playerController = GameObject.Find("Player").GetComponent<PlayerController>();
  11. healthBar = GameObject.Find("HealthBar").GetComponent<Slider>();
  12. if (healthBar)
  13. {
  14. healthBar.maxValue = maxHealth;
  15. }
  16. }
  17. public void Update()
  18. {
  19. if(playerController && playerController.bHasBeenDamaged)
  20. {
  21. healthBar.value = playerController.health;
  22. }
  23. }
  24. }