From 7f2e3101a7e7ea067eff0be0ca5ce6134b2b9468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=86=E1=85=B5=E1=86=AB?= =?UTF-8?q?=E1=84=80=E1=85=AE?= Date: Fri, 3 Jul 2026 17:34:25 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20=EC=BA=90=EB=A6=AD=ED=84=B0=20=EB=8D=B0?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EB=A9=94=EC=84=9C=EB=93=9C=20debug=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=EC=9C=BC=EB=A1=9C=20=EC=9E=84=EC=8B=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unity-client/Assets/Scripts/PlayerMove.cs | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/unity-client/Assets/Scripts/PlayerMove.cs b/unity-client/Assets/Scripts/PlayerMove.cs index dc10080..78a9f4c 100644 --- a/unity-client/Assets/Scripts/PlayerMove.cs +++ b/unity-client/Assets/Scripts/PlayerMove.cs @@ -29,6 +29,7 @@ public class PlayerMove : MonoBehaviour // 이동 관련 변수 [SerializeField] private float speed = 5f; [SerializeField] public int hp = 5; + private int maxHp; private bool isFacingRight = false; private int currentAnimationState = -1; @@ -54,10 +55,21 @@ public class PlayerMove : MonoBehaviour transform.localScale = initialScale; animator = GetComponentInChildren(); + maxHp = hp; } private void Update() { + if (hp <= 0) + { + if (animator != null) + { + animator.SetBool("1_Move", false); + } + + return; + } + InputContoller.UpdateInput(ref _inputs); // 좌우 방향 전환 (Flip) @@ -94,6 +106,13 @@ public class PlayerMove : MonoBehaviour private void Move() { if (rb == null) return; + + if (hp <= 0) + { + rb.linearVelocity = new Vector2(0f, rb.linearVelocity.y); + return; + } + rb.linearVelocity = new Vector2(_inputs.PlayerMove.x * speed, rb.linearVelocity.y); } @@ -104,4 +123,63 @@ public class PlayerMove : MonoBehaviour scale.x *= -1f; transform.localScale = scale; } + + // 데미지를 입는 메서드 + public void TakeDamage(int damage) + { + if (hp <= 0) return; // 이미 사망한 경우 제외 + + hp -= damage; + if (hp < 0) hp = 0; + + Debug.Log($"플레이어가 {damage} 데미지를 입었습니다. 현재 체력: {hp}"); + + if (animator != null) + { + if (hp <= 0) + { + animator.SetTrigger("4_Death"); + Debug.Log("플레이어가 사망했습니다."); + } + else + { + animator.SetTrigger("3_Damaged"); + } + } + } + + // 인스펙터 우클릭 메뉴에서 데미지를 테스트할 수 있는 기능 추가 + [ContextMenu("Debug/Take 5 Damage")] + public void DebugTake5Damage() + { + TakeDamage(5); + } + + [ContextMenu("Debug/Restore HP")] + public void DebugRestoreHP() + { + hp = maxHp; + if (animator != null) + { + animator.Rebind(); + animator.Update(0f); + } + Debug.Log($"플레이어 체력이 {hp}로 회복되었습니다."); + } + + // 임시 디버그용 화면 버튼 (게임 실행 시 화면 좌측 상단에 뜸) + private void OnGUI() + { + GUI.backgroundColor = Color.red; + if (GUI.Button(new Rect(10, 10, 180, 50), "Debug: Take 5 Damage")) + { + TakeDamage(5); + } + + GUI.backgroundColor = Color.green; + if (GUI.Button(new Rect(10, 70, 180, 50), "Debug: Restore HP")) + { + DebugRestoreHP(); + } + } } \ No newline at end of file