Added lots of examples for editor customization
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using Data;
|
||||
using Events;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class HealthBar : MonoBehaviour
|
||||
{
|
||||
[Header("Events")]
|
||||
[SerializeField] private EventBroker eventBroker;
|
||||
|
||||
[Header("Values")]
|
||||
[SerializeField] private FloatValue maxHealth;
|
||||
[SerializeField] private FloatValue currentHealth;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private Image fillingImage;
|
||||
[SerializeField] private TextMeshProUGUI deadMessageText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
fillingImage.type = Image.Type.Filled;
|
||||
fillingImage.fillMethod = Image.FillMethod.Horizontal;
|
||||
fillingImage.fillOrigin = 0;
|
||||
deadMessageText.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
eventBroker.PlayerDied += OnPlayerDied;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
eventBroker.PlayerDied -= OnPlayerDied;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
fillingImage.fillAmount = currentHealth.Value / maxHealth.Value;
|
||||
}
|
||||
|
||||
private void OnPlayerDied()
|
||||
{
|
||||
fillingImage.fillAmount = 0.0f;
|
||||
currentHealth.Value = 0.0f;
|
||||
deadMessageText.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user