| 1234567891011121314151617181920212223242526272829 |
- using UnityEngine;
- using UnityEngine.UI;
- public class HealthBar : MonoBehaviour
- {
- public PlayerController playerController;
- public Slider healthBar;
- public float maxHealth;
- private void Start()
- {
- playerController = GameObject.Find("Player").GetComponent<PlayerController>();
- healthBar = GameObject.Find("HealthBar").GetComponent<Slider>();
- if (healthBar)
- {
- healthBar.maxValue = maxHealth;
- }
- }
- public void Update()
- {
- if(playerController && playerController.bHasBeenDamaged)
- {
- healthBar.value = playerController.health;
- }
- }
- }
|