웅냥
This commit is contained in:
31
Assets/Scripts/Unicorn/HpBar.cs
Normal file
31
Assets/Scripts/Unicorn/HpBar.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unicorn
|
||||
{
|
||||
public class HpBar : MonoBehaviour
|
||||
{
|
||||
private LivingEntity _parent;
|
||||
public GameObject fill;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!transform.parent.TryGetComponent(out _parent))
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
UpdateHealth();
|
||||
}
|
||||
|
||||
public void UpdateHealth()
|
||||
{
|
||||
var scale = Math.Max(_parent.health, 0f) / _parent.maxHealth;
|
||||
fill.transform.localScale = new Vector3(scale, 1, 1);
|
||||
fill.transform.localPosition = new Vector3((scale-1) / 2, 0, 0);
|
||||
|
||||
//1 -> 0
|
||||
//0 -> -0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user