Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / UIObserver.cs
@Rackday Rackday on 3 Sep 902 bytes Minor Update
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);
    }


}