3DSurvivalGame / Assets /Scripts /ResourceHealthBar.cs
doc2txt's picture
1
3497d64
raw
history blame contribute delete
No virus
695 Bytes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ResourceHealthBar : MonoBehaviour
{
private Slider slider;
private float currentHealth, maxHealth;
public GameObject globalState;
void Awake()
{
slider = GetComponent<Slider>();
}
private void Update() {
currentHealth = globalState.GetComponent<GlobalState>().resourceHealth;
maxHealth = globalState.GetComponent<GlobalState>().resourceMaxHealth;
float fillValue = currentHealth/maxHealth;
slider.value = fillValue;
// healthCounter.text = currentHealth+"/"+maxHealth;
}
}