몬스터 위치에 데미지 UI 출력
public class UI_Damage : Singleton<UI_Damage>
{
private GameObject damagePrefab;
protected override void Awake()
{
damagePrefab = Resources.Load<GameObject>("Prefabs/UI/DamageText");
}
public void DamagePool(int damage, Vector3 position)
{
Poolable damagePool = PoolManager.Instance.Get(damagePrefab);
Damage damageText = damagePool.GetComponent<Damage>();
damageText.ShowDamage(damage, position, damagePool);
}
}
public class Damage : MonoBehaviour
{
TextMeshPro damageTxt;
private void Awake()
{
damageTxt = GetComponent<TextMeshPro>();
}
public void ShowDamage(int damage, Vector3 position, Poolable pool)
{
damageTxt.text = damage.ToString();
transform.position = position;
transform.DOMoveY(transform.position.y + 1f, 1f).SetEase(Ease.OutQuart).OnComplete(() =>
{
PoolManager.Instance.Release(pool);
});
}
}
몬스터 객체에 데미지 UI를 띄울 빈 객체를 만들어서 위치를 넘겨주도록 했다.