250401 TIL

박소희·2025년 4월 1일

Unity_7기

목록 보기
59/94

몬스터 위치에 데미지 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를 띄울 빈 객체를 만들어서 위치를 넘겨주도록 했다.

0개의 댓글