Skip to content

Commit

Permalink
lerp health bar
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Dec 10, 2021
1 parent 8a271ae commit 0ef85da
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -59,11 +59,8 @@ void GetNextPath()

public void Damage(int damage)
{

Health -= damage;

healthBar.fillAmount = (float)Health / maxHealth;

if (Health <= 0)
{
Health = 0;
Expand Down

0 comments on commit 0ef85da

Please sign in to comment.