using System.Collections; using System.Collections.Generic; using System.Data; using UnityEngine; public class UIObserver : MonoBehaviour, IObserver { // Start is called before the first frame update void Start() { NPCManager.Instance.RegisterObservers(this); } // Update is called once per frame void Update() { } public void OnNotify(object obj) { EnemyNPCContoller controller = obj as EnemyNPCContoller; if (controller != null) { float fillAmount = controller.CurrentHealth() / controller.MaxHealth; controller.HealthBarImage.fillAmount = fillAmount; } else { Debug.LogError($"Missing or Invalid: {nameof(EnemyNPCContoller)}"); } } public void OnDestroy() { NPCManager.Instance.UnregisterObserver(this); } }