-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusIndicator.cs
More file actions
32 lines (25 loc) · 884 Bytes
/
Copy pathStatusIndicator.cs
File metadata and controls
32 lines (25 loc) · 884 Bytes
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
using UnityEngine;
//using System.Collections;
using UnityEngine.UI;
public class StatusIndicator : MonoBehaviour {
[SerializeField]
private RectTransform healthBarRect;
private Text healthText;
void Start()
{
if (healthBarRect == null)
{
Debug.LogError("STATUS INDICATOR: No health bar object referenced!");
}
if (healthText == null)
{
Debug.LogError("STATUS INDICATOR: No health text object referenced!");
}
}
public void SetHealth(int _cur, int _max)
{
float _value = (float) _cur / _max;
healthBarRect.localScale = new Vector3(_value, healthBarRect.localScale.y, healthBarRect.localScale.z); //this will change the scale of our health bar
healthText.text = _cur + "/" + _max + "HP";//change our text
}
}