Skip to content

Commit

Permalink
Merge pull request #102 from hackerspace-ntnu/feature/tween-health-bar
Browse files Browse the repository at this point in the history
Tween health bar transitions
  • Loading branch information
toberge committed Mar 1, 2023
2 parents e050b3f + b70adb0 commit e584c52
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Assets/Scripts/UI/HUDController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

Expand All @@ -14,11 +12,14 @@ public class HUDController : MonoBehaviour
[SerializeField]
private TMP_Text deathText;

[SerializeField]
private float tweenDuration = .07f;

public void UpdateHealthBar(float currentHealth, float maxHealth)
{
float width = (Mathf.Max(currentHealth, 0f) / maxHealth) * 200f;
healthBar.sizeDelta = new Vector2(width, healthBar.sizeDelta.y);
healthBar.anchoredPosition = new Vector2(25 + width / 2f, healthBar.anchoredPosition.y);
LeanTween.size(healthBar, new Vector2(width, healthBar.sizeDelta.y), tweenDuration);
LeanTween.move(healthBar, new Vector2(25 + width / 2f, healthBar.anchoredPosition.y), tweenDuration);
}

public void DisplayDeathScreen(PlayerIdentity killer)
Expand Down

0 comments on commit e584c52

Please sign in to comment.