Player = DamagedState, DeadState 상태 추가

This commit is contained in:
Mingu Kim
2025-08-22 20:33:29 +09:00
parent d8c356e841
commit cf41a64529
5 changed files with 125 additions and 82 deletions

View File

@@ -1,6 +1,5 @@
using System;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
// 컴포넌트 프로퍼티
@@ -50,53 +49,21 @@ public class PlayerMove : MonoBehaviour
void FixedUpdate()
{
float h = Input.GetAxisRaw("Horizontal");
RigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
if (RigidBody.linearVelocity.x > maxSpeed)
{
RigidBody.linearVelocity = new Vector2(maxSpeed, RigidBody.linearVelocity.y);
}
else if (RigidBody.linearVelocity.x < -maxSpeed)
{
RigidBody.linearVelocity = new Vector2(-maxSpeed, RigidBody.linearVelocity.y);
}
// FixedUpdate 로직은 이제 사용하지 않습니다.
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
// FSM에 피격 로직 추가
// _stateMachine.SetTransition(new DamagedState(this, collision.transform.position));
// 중복 호출 제거, 피격 위치를 전달하는 메서드만 사용
_stateMachine.SetTransition(State.Damaged, collision.transform.position);
}
}
void OnDamaged(Vector2 targetPosition)
{
// OnDamaged 로직은 DamagedState의 Enter()로 이동
// 기존 Invoke("OffDamaged", 1)는 DamagedState 내부에서 처리
}
void OffDamaged()
{
// OffDamaged 로직은 DamagedState의 Exit()로 이동
}
// 공격 애니메이션 이벤트에서 호출될 함수
public void StartAttackHitbox()
// 플레이어 오브젝트를 파괴하는 메서드
public void Die()
{
if (attackCollider != null)
{
attackCollider.enabled = true;
}
Destroy(gameObject);
}
public void EndAttackHitbox()
{
if (attackCollider != null)
{
attackCollider.enabled = false;
}
}
}
}