Repository navigation
Expand file tree
/
Copy pathBossUI.cs
More file actions
48 lines (38 loc) · 1.31 KB
/
Copy pathBossUI.cs
File metadata and controls
48 lines (38 loc) · 1.31 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class BossUI: MonoBehaviour {
[SerializeField] Image healthBar;
CanvasGroup canvasGroup;
Tweener healthBarTween;
int startHealth;
void Awake() {
canvasGroup = GetComponent<CanvasGroup>();
canvasGroup.alpha = 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
healthBar.fillAmount = 0f;
WaveManager.I.OnBossSpawned += OnBossSpawned;
}
void OnBossSpawned() {
startHealth = Boss.I.Health.HP;
Boss.I.Health.OnDied += Hide;
Boss.I.Health.OnDamage += OnDamage;
Player.I.Health.OnDied += Hide;
Show();
}
async void Show() {
canvasGroup.DOFade(1f, 0.5f).SetEase(Ease.InOutSine);
await healthBar.DOFillAmount(1f, 1.5f).SetEase(Ease.Linear).AsyncWaitForCompletion();
healthBarTween = healthBar.DOFillAmount(HealthFill, 0.2f).SetEase(Ease.InOutQuad).SetAutoKill(false);
}
void OnDamage() {
if (healthBarTween == null) return;
healthBarTween.ChangeValues(healthBar.fillAmount, HealthFill, 0.2f).Play();
}
void Hide() {
healthBarTween.Kill(true);
canvasGroup.DOFade(0f, 0.5f);
}
float HealthFill => (float)Boss.I.Health.HP / (float)startHealth;
}