using UnityEngine; using UnityEngine.UI; public class HpBar : IVTraceTarget { private Slider sldHp; public override void SetCameraTarget(Camera cammain, Camera camui, RectTransform trfpr, Transform trftarget, float foffsety) { base.SetCameraTarget(cammain, camui, trfpr, trftarget, foffsety); sldHp = GetComponent(); } public void ShowHpBar(float fhp) { if (fhp <= 0.06f) sldHp.value = 0.06f; else if (fhp <= 0) sldHp.value = 0f; else sldHp.value = fhp; if (!gameObject.activeSelf) { SetPosition(); gameObject.SetActive(true); } else { CancelInvoke(nameof(HideHpBar)); } Invoke(nameof(HideHpBar), 0.6f); } public void HideHpBar() { CancelInvoke(nameof(HideHpBar)); gameObject.SetActive(false); } }