using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TMPro;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class HealthDisplay : MonoBehaviour
|
{
|
private GameObject _playerGO;
|
private Damageable playerDamage;
|
public TextMeshProUGUI healthText;
|
public Slider healthSlider;
|
|
public GameObject PlayerGO
|
{
|
get
|
{
|
if (_playerGO == null)
|
{
|
_playerGO = GameObject.Find("Player");
|
}
|
return _playerGO;
|
}
|
private set { _playerGO = value; }
|
}
|
|
private void Awake()
|
{
|
PlayerGO = GameObject.Find("Player");
|
playerDamage = _playerGO.GetComponent<Damageable>();
|
//originalRect = healthImage.rectTransform.rect;
|
}
|
|
private void Update()
|
{
|
healthText.text = "Health: " + playerDamage.Health;
|
healthSlider.value = (float)playerDamage.Health / (float)playerDamage.MaxHealth;
|
//healthImage.rectTransform.sizeDelta = new Vector2(originalRect.width * ((float)playerDamage.Health / (float)playerDamage.MaxHealth), originalRect.height);
|
}
|
}
|