Completed course 2 adn 3, working on 4
This commit is contained in:
31
Assets/Scripts/UnitHealthBar.cs
Normal file
31
Assets/Scripts/UnitHealthBar.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UnitHealthBar : MonoBehaviour
|
||||
{
|
||||
public GameObject healthContainer;
|
||||
public RectTransform healthFill;
|
||||
private float maxSize;
|
||||
void Awake()
|
||||
{
|
||||
maxSize = healthFill.sizeDelta.x;
|
||||
healthContainer.SetActive(false);
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void UpdateHealthBar(int curHp, int maxHp)
|
||||
{
|
||||
healthContainer.SetActive(true);
|
||||
float healthPercentage = (float)curHp / (float)maxHp;
|
||||
healthFill.sizeDelta = new Vector2(maxSize * healthPercentage, healthFill.sizeDelta.y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user