proto_fighter/Assets/Scripts/HealthBar.cs

24 lines
495 B
C#
Raw Normal View History

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());
}
}