From 0ef85da9b0d86eda28cab471e55783096dc59135 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Thu, 9 Dec 2021 21:21:49 -0500 Subject: [PATCH] lerp health bar --- Assets/Scripts/Enemy.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs index ee9ee8a..967f823 100644 --- a/Assets/Scripts/Enemy.cs +++ b/Assets/Scripts/Enemy.cs @@ -13,8 +13,6 @@ public class Enemy : MonoBehaviour private int pathIndex = 0; public int currencyDrop = 10; public int damage = 1; - - [Header("Unity stuff")] public Image healthBar; // Start is called before the first frame update @@ -35,6 +33,8 @@ void Update() // Debug.Log(dir); transform.Translate(dir.normalized * speed * Time.deltaTime); + healthBar.fillAmount = Mathf.Lerp(healthBar.fillAmount, (float)Health / maxHealth, 10f * Time.deltaTime); + // Give a new path node if the enemy has reach it if (Vector3.Distance(position, target) <= 0.01f) { @@ -59,11 +59,8 @@ void GetNextPath() public void Damage(int damage) { - Health -= damage; - healthBar.fillAmount = (float)Health / maxHealth; - if (Health <= 0) { Health = 0;