EerieVillage/Assets/Scripts/Gameplay/EnemyDeath.cs

48 lines
2.1 KiB
C#

using Platformer.Core;
using Platformer.Mechanics;
using UnityEngine;
namespace Platformer.Gameplay
{
/// <summary>
/// Fired when the health component on an enemy has a hitpoint value of 0.
/// BT104 (PD 명시 2026-05-08): Enemy 사망 시 patrol·시각 영역 비활성 + 1초 후 GameObject Destroy
/// </summary>
public class EnemyDeath : Simulation.Event<EnemyDeath>
{
public EnemyController enemy;
public override void Execute()
{
// BT12-Dev 진단 (2026-05-10 PD A+B) — EnemyDeath.Execute 호출 검증.
// 회수: PD 사망 원인 확정 후 본 PM revert commit.
Debug.Log($"[EnemyDeath][Execute] enemy={(enemy != null ? enemy.name : "NULL")} collider={(enemy != null && enemy._collider != null ? enemy._collider.enabled.ToString() : "NULL")} t={Time.time:F2}");
if (enemy == null) return;
// 충돌·이동·patrol 영역 비활성
if (enemy._collider != null) enemy._collider.enabled = false;
if (enemy.control != null) enemy.control.enabled = false;
enemy.enabled = false; // EnemyController patrol 영역 정지
// BT105 — 제자리 사망 (PD 명시 2026-05-08): Rigidbody2D simulated = false → gravity X·물리 미참여
var body = enemy.GetComponent<Rigidbody2D>();
if (body != null) body.simulated = false;
// death 애니메이션 트리거 (Enemy.controller 영역의 'death' parameter)
var animator = enemy.GetComponent<Animator>();
if (animator != null) animator.SetTrigger("death");
// 사운드
if (enemy._audio != null && enemy.ouch != null)
enemy._audio.PlayOneShot(enemy.ouch);
// 1초 후 GameObject 영역 Destroy (사망 애니메이션 시간)
Object.Destroy(enemy.gameObject, 1f);
// BT12-MVP-A 영역 신규 (2026-05-08) — 적 처치 시 EXP 발급
var player = Object.FindFirstObjectByType<PlayerController>();
EerieVillage.Progression.ExperienceSystem.OnEnemyKilled(enemy, player);
}
}
}