24 lines
495 B
C#
24 lines
495 B
C#
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
[RequireComponent(typeof(Image))]
|
||
|
public class HealthBar : MonoBehaviour
|
||
|
{
|
||
|
private Image _healthBar;
|
||
|
private Material _material;
|
||
|
|
||
|
public Player target;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
_healthBar = GetComponent<Image>();
|
||
|
_material = Instantiate(_healthBar.material);
|
||
|
_healthBar.material = _material;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
_material.SetFloat("_Value", target.HealthPercent());
|
||
|
}
|
||
|
}
|