feat: 몬스터 피격시 데미지 텍스트 이펙트 추가

This commit is contained in:
aube.lee
2025-02-26 11:20:24 +09:00
parent f7cdaa7178
commit c8059ce769
10 changed files with 466 additions and 8 deletions

View File

@@ -29,13 +29,17 @@ namespace TON
// TODO: 장비 공격력 반영 필요
// float damage = damageCalculator.CalculateBaseDamage(playerData.attackPower, playerData.equipmentAttack, playerData.defensivePower);
// 몬스터 방어력 의도값 계산
MonsterBase monsterBase = collision.GetComponent<MonsterBase>();
// 몬스터가 이전 피격으로 이미 죽은 경우우
if (monsterBase.currentHP <= 0)
return;
// 몬스터 방어력 의도값 계산
float calcMonsterDefence = monsterBase.defencePower / (monsterBase.defencePower + monsterBase.defenceIntention);
float damage = damageCalculator.CalculateBaseDamage(playerData.attackPower, 0, calcMonsterDefence);
// 치명타 적용 (캐릭터는 적용)
damage = damageCalculator.ApplyCriticalDamage(damage);
damage = damageCalculator.ApplyCriticalDamage(damage, collision.transform.position);
collision.GetComponent<IDamage>().ApplyDamage(damage);
}

View File

@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace TON
{
public class DamageEffect : PoolAble
{
public TextMeshProUGUI textMesh;
public float floatSpeed = 1.0f;
public float duration = 1.0f;
private float timer = 0f;
private void Awake()
{
// Canvas의 Render Mode가 World Space일 경우, Main Camera를 Event Camera로 설정
Canvas canvas = gameObject.GetComponentInChildren<Canvas>();
if (canvas.renderMode == RenderMode.WorldSpace && canvas.worldCamera == null)
{
Debug.Log("test camera");
canvas.worldCamera = Camera.main; // Main Camera 할당
}
}
public void SetDamage(int damage, bool isCritical)
{
// 데미지 값에 따라 색상이나 크기 변경 가능
textMesh.text = string.Format("{0:#,###}", damage);
// 크리티컬 히트일 경우 색상 변경
if (isCritical)
textMesh.color = Color.yellow;
else
textMesh.color = Color.white;
// 타이머 리셋
timer = 0f;
}
void Update()
{
// 위로 떠오르는 효과
transform.position += Vector3.up * floatSpeed * Time.deltaTime;
// 시간에 따른 투명도 조절
timer += Time.deltaTime;
float alpha = 1.0f - (timer / duration);
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, alpha);
// 지속 시간이 지나면 비활성화
if (timer >= duration)
{
gameObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c86fdd904c9e8d41a93d1249c02a506
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: