miepzerino
2023-12-15 24253ea93a51232da89a429aa4964578446bca44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
    }
}