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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
using UnityEngine;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
[SerializeField]
private Image maskBar;
[SerializeField]
private Image healthBar;
[SerializeField]
private Image armorBar;
[SerializeField]
private Image shieldBar;
[SerializeField]
private Image dmgBar;
[SerializeField]
private Image slowImageLeft;
[SerializeField]
private Image slowImageRight;
[SerializeField]
private GameObject BleedImage;
[SerializeField]
private GameObject BurnImage;
[SerializeField]
private GameObject PoisonImage;
[SerializeField]
private Text bleedText;
[SerializeField]
private Text burnText;
[SerializeField]
private Text poisonText;
[SerializeField]
private Image fortImageLeft;
[SerializeField]
private Image fortImageRight;
[SerializeField]
private Image hasteImageLeft;
[SerializeField]
private Image hasteImageRight;
private float maxHp;
private float health;
private float armor;
private float shield;
private float dmg;
private float barScaler = 100f;
private void Update()
{
if (dmg > health + armor + shield)
{
dmg = Mathf.Clamp(dmg - 4f * Time.deltaTime, health + armor + shield, dmg);
dmgBar.rectTransform.sizeDelta = new Vector2(dmg, 0.25f);
}
}
public void SetHealth(int max, int heal, int armr, int shld, int scaleDegree)
{
barScaler = 10f * Mathf.Pow(10f, scaleDegree);
maxHp = (float)max / barScaler;
dmg = maxHp;
health = (float)heal / barScaler;
armor = (float)armr / barScaler;
shield = (float)shld / barScaler;
maskBar.rectTransform.localScale = new Vector3(3f / (maxHp + 3f), 1f, 1f);
maskBar.rectTransform.sizeDelta = new Vector2(maxHp, 0.25f);
dmgBar.rectTransform.sizeDelta = new Vector2(dmg, 0.25f);
UpdateHealth(heal, armr, shld, 0f, isBleeding: false, isBurning: false, isPoisoned: false, 0, 0, 0);
}
public void UpdateHealth(int heal, int armr, int shld, float currentSlow, bool isBleeding, bool isBurning, bool isPoisoned, int currentBleed, int currentBurn, int currentPoison)
{
health = (float)heal / barScaler;
armor = (float)armr / barScaler;
shield = (float)shld / barScaler;
healthBar.rectTransform.sizeDelta = new Vector2(health, 0.25f);
armorBar.rectTransform.sizeDelta = new Vector2(armor, 0.25f);
shieldBar.rectTransform.sizeDelta = new Vector2(shield, 0.25f);
armorBar.rectTransform.localPosition = new Vector3(health - maskBar.rectTransform.sizeDelta.x / 2f, 0f, 0f);
shieldBar.rectTransform.localPosition = new Vector3(health + armor - maskBar.rectTransform.sizeDelta.x / 2f, 0f, 0f);
Image image = slowImageLeft;
float fillAmount = (slowImageRight.fillAmount = currentSlow);
image.fillAmount = fillAmount;
BleedImage.SetActive(isBleeding);
bleedText.gameObject.SetActive(isBleeding);
bleedText.text = currentBleed.ToString();
BurnImage.SetActive(isBurning);
burnText.gameObject.SetActive(isBurning);
burnText.text = currentBurn.ToString();
PoisonImage.SetActive(isPoisoned);
poisonText.gameObject.SetActive(isPoisoned);
poisonText.text = currentPoison.ToString();
}
public void UpdateSlow(float currentSlow)
{
Image image = slowImageLeft;
float fillAmount = (slowImageRight.fillAmount = currentSlow);
image.fillAmount = fillAmount;
}
public void UpdateBleed(bool status, int amt)
{
BleedImage.SetActive(status);
bleedText.gameObject.SetActive(status);
bleedText.text = amt.ToString();
}
public void UpdateBurn(bool status, int amt)
{
BurnImage.SetActive(status);
burnText.gameObject.SetActive(status);
burnText.text = amt.ToString();
}
public void UpdatePoison(bool status, int amt)
{
PoisonImage.SetActive(status);
poisonText.gameObject.SetActive(status);
poisonText.text = amt.ToString();
}
public void UpdateFortified(float fortTime)
{
Image image = fortImageLeft;
float fillAmount = (fortImageRight.fillAmount = fortTime * 0.083333f);
image.fillAmount = fillAmount;
}
public void UpdateHaste(float hastePercentage)
{
Image image = hasteImageLeft;
float fillAmount = (hasteImageRight.fillAmount = hastePercentage);
image.fillAmount = fillAmount;
}
}
|