AttackState 공격 시 공격 궤적 스프라이트 노출되도록 수

This commit is contained in:
Mingu Kim
2025-08-22 22:02:35 +09:00
parent 8790e3982a
commit 3e551e99d0
4 changed files with 45 additions and 18 deletions

View File

@@ -43,8 +43,17 @@ public class PlayerMove : MonoBehaviour
_stateMachine = new StateMachine(State.IDLE, this);
// 공격 콜라이더 참조
attackCollider = GetComponentInChildren<Collider2D>();
// AttackArea 게임 오브젝트를 찾고 그 자식에서 Collider2D를 가져옵니다.
Transform attackAreaTransform = transform.Find("AttackArea");
if (attackAreaTransform != null)
{
attackCollider = attackAreaTransform.GetComponent<Collider2D>();
}
if (attackCollider == null)
{
Debug.LogError("AttackArea child object or Collider2D component not found!");
}
}
void Start()
@@ -57,11 +66,6 @@ public class PlayerMove : MonoBehaviour
_stateMachine.Update();
}
void FixedUpdate()
{
// FixedUpdate 로직은 이제 사용하지 않습니다.
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))

View File

@@ -98,6 +98,10 @@ public class IdleState : IState
{
return State.MOVE;
}
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
return State.IDLE;
}
}
@@ -151,6 +155,10 @@ public class MoveState : IState
{
return State.IDLE;
}
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
return State.MOVE;
}
}
@@ -187,6 +195,10 @@ public class JumpState : IState
public State CheckTransition()
{
if (Input.GetMouseButtonDown(0))
{
return State.Attack;
}
if (_player.RigidBody.linearVelocity.y < 0)
{
Debug.DrawRay(_player.RigidBody.position, Vector3.down, Color.green);
@@ -204,6 +216,8 @@ public class JumpState : IState
public class AttackState : IState
{
private PlayerMove _player;
private float _attackDuration = 0.5f; // 공격 지속 시간
private float _attackStartTime;
public AttackState(PlayerMove player)
{
@@ -212,21 +226,30 @@ public class AttackState : IState
public void Enter()
{
_player.Animator.SetTrigger("Attack");
// 애니메이션 없이 오브젝트만 활성화
_player.attackCollider.gameObject.SetActive(true);
_attackStartTime = Time.time;
}
public void Update()
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
if (horizontalInput != 0)
{
Vector3 newScale = _player.transform.localScale;
newScale.x = horizontalInput > 0 ? -1f : 1f;
_player.transform.localScale = newScale;
}
}
public void Exit()
{
_player.attackCollider.gameObject.SetActive(false);
}
public State CheckTransition()
{
AnimatorStateInfo stateInfo = _player.Animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.normalizedTime >= 1.0f && !stateInfo.IsTag("Attack"))
if (Time.time >= _attackStartTime + _attackDuration)
{
return State.IDLE;
}