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

public class HPBar : MonoBehaviour
{
    GameObject thisObj;
    GameObject BGOBJ;
    GameObject gaugeImgOBJ;


    void Start()
    {
        thisObj = 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 = thisObj.GetComponent<states>().MaxHP;
        float nowHP = thisObj.GetComponent<states>().getnowHP();
        gaugeImgOBJ.GetComponent<Image>().fillAmount = nowHP / maxHP;
    }
}
