using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EnemyHPBar : MonoBehaviour
{
    GameObject EnemyOBJ;
    GameObject BGOBJ;
    GameObject gaugeImgOBJ;
    

    void Start()
    {
        EnemyOBJ = transform.parent.gameObject;
        BGOBJ = transform.GetChild(0).gameObject;
        gaugeImgOBJ = BGOBJ.transform.GetChild(0).gameObject;
        Vector3 v = Camera.main.transform.position - transform.position;
        v.x = v.z = 0.0f;
        transform.LookAt(Camera.main.transform.position - v);
        transform.Rotate(0,180,0);
    }

    void Update()
    {
        Vector3 v = Camera.main.transform.position - transform.position;
        v.x = v.z = 0.0f;
        transform.LookAt(Camera.main.transform.position - v);
        transform.Rotate(0,180,0);

        float maxHP = EnemyOBJ.GetComponent<Enemy>().EnemyMaxHP;
        float nowHP = EnemyOBJ.GetComponent<Enemy>().getnowHP();
        gaugeImgOBJ.GetComponent<Image>().fillAmount = nowHP / maxHP;
    }
}
