using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class EnemyHealthBar : MonoBehaviour
{
    [SerializeField] private Image _healthStrip;
    [SerializeField] private TextMeshProUGUI _npcName;

    private Camera _camera;
    
    public void SetName(string npcName)
    {
        _camera = Camera.main;
        gameObject.SetActive(true);
        _npcName.text = npcName;
    }

    public void SetRatio(float ratio)
    {
        gameObject.SetActive(ratio > 0);
        _healthStrip.fillAmount = ratio;
    }

    private void Update()
    {
        var rotation = _camera.transform.rotation;
        transform.LookAt(transform.position + rotation * Vector3.forward, rotation * Vector3.up);
    }
}
