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

@@ -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;
}