Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HealthBar : MonoBehaviour
- {
- private Slider slider;
- public Text healthCounter;
- public GameObject playerState;
- private float currentHealth, maxHealth;
- void Awake()
- {
- slider = GetComponent<Slider>();
- }
- void Update()
- {
- currentHealth = playerState.GetComponent<PlayerState>().currentHealth;
- maxHealth = playerState.GetComponent<PlayerState>().maxHealth;
- float fillValue = currentHealth / maxHealth; // 100/100
- slider.value = fillValue;
- healthCounter.text = currentHealth + "/" + maxHealth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement