Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HealthUI : MonoBehaviour {
- public Slider slider;
- // Use this for initialization
- void Start ()
- {
- MessageHandler msgHandler = GetComponent<MessageHandler>();
- if (msgHandler)
- {
- msgHandler.RegisterDelegate(RecieveMessage);
- }
- }
- void RecieveMessage(MessageType msgType, GameObject go, MessageData msgData)
- {
- switch (msgType)
- {
- case MessageType.HEALTHCHANGED:
- HealthData hpData = msgData as HealthData;
- if (hpData != null)
- {
- UpdateUI(hpData.maxHealth, hpData.curHealth);
- }
- break;
- }
- }
- void UpdateUI(int maxHealth, int curHealth)
- {
- slider.value = (1.0f / maxHealth) * curHealth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment