forked from Hummus-1/Prototipo-Interfaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthBar.cs
26 lines (23 loc) · 863 Bytes
/
HealthBar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class HealthBar : MonoBehaviour {
public Image healthBarImage;
private Player player;
void Start() {
player = GameObject.FindWithTag("Player").GetComponent<Player>();
}
// Update is called once per frame
public void UpdateHealthBar() {
float duration = 0.75f * (player.health / player.maxHealth);
healthBarImage.DOFillAmount( player.health / player.maxHealth, duration);
Color newColor = Color.green;
if ( player.health < player.maxHealth * 0.25f ) {
newColor = Color.red;
} else if ( player.health < player.maxHealth * 0.66f ) {
newColor = new Color( 1f, .64f, 0f, 1f );
} healthBarImage.DOColor( newColor, duration );
}
}