2026-06-02 사운드 추가
This commit is contained in:
@@ -126,6 +126,7 @@ public class PlayerController : MonoBehaviour,IDamageable
|
||||
[SerializeField] private bool _showAttackDebug = true; // OnGUI에 공격 정보 패널 표시 여부
|
||||
private float _attackStartTime = -1f; // 액션 시작 시각 (디버그 elapsed 계산)
|
||||
private bool _hitFired; // 현재 액션에서 hit이 이미 발화됐는지
|
||||
private bool _hitSoundPlayed; // 현재 hit window에서 타격음을 이미 재생했는지 (적 여러 명 동시 타격 시 중복 방지)
|
||||
|
||||
private readonly List<RaycastHit2D> _castResults = new(); // Cast 결과 버퍼 (GC 회피용)
|
||||
private Rigidbody2D _rb;
|
||||
@@ -923,6 +924,13 @@ private void OnAttackHit(IDamageable target)
|
||||
{
|
||||
if (target is Enemy enemy)
|
||||
_lastHitEnemy = enemy;
|
||||
|
||||
// 실제 적중이 일어난 순간에만 타격음 재생. 한 hit window에서 한 번만.
|
||||
if (!_hitSoundPlayed)
|
||||
{
|
||||
PlayHitSound(_lastHitData);
|
||||
_hitSoundPlayed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateAttackHitbox(ActionData data)
|
||||
@@ -935,11 +943,27 @@ private void ActivateAttackHitbox(ActionData data)
|
||||
_lastHitCenter = transform.TransformPoint(localPosition);
|
||||
_lastHitTime = Time.time;
|
||||
_hitFired = true;
|
||||
_hitSoundPlayed = false; // 새 hit window 시작 — 타격음 재생 가드 초기화
|
||||
|
||||
Vector2 sourcePosition = _rb != null ? _rb.position : (Vector2)transform.position;
|
||||
_attackHitbox.Activate(data, localPosition, hitVelocity, sourcePosition, hitTargetPosition, data.CorrectHitTargetY, _groundLayer.value, _enemyLayer);
|
||||
|
||||
SpawnHitEffect(data);
|
||||
PlayAttackSound(data);
|
||||
}
|
||||
|
||||
// 무기 모션(휘두름/발사) 사운드 재생. 적중 여부와 무관하게 hit window 활성 시 항상 재생.
|
||||
private void PlayAttackSound(ActionData data)
|
||||
{
|
||||
if (data.AttackSound == null || AudioManager.Instance == null) return;
|
||||
AudioManager.Instance.PlaySfx(data.AttackSound, data.AttackSoundVolume);
|
||||
}
|
||||
|
||||
// 타격 사운드 재생. 실제 적중(OnAttackHit) 시점에만 호출된다. AudioManager의 SFX 풀을 통해 믹서로 라우팅된다.
|
||||
private void PlayHitSound(ActionData data)
|
||||
{
|
||||
if (data.HitSound == null || AudioManager.Instance == null) return;
|
||||
AudioManager.Instance.PlaySfx(data.HitSound, data.HitSoundVolume);
|
||||
}
|
||||
|
||||
// hit 발동 시점에 이펙트 프리팹 생성.
|
||||
|
||||
Reference in New Issue
Block a user