플랫폼별 입력 화장성을 위해 Inputs구조체 추가 및 InputControoller 추가
- 캐릭터 이동이 정상적으로 작동하지 않는 문제 수정
This commit is contained in:
@@ -67,6 +67,8 @@ public interface IState
|
||||
|
||||
public class IdleState : IState
|
||||
{
|
||||
private static readonly int IsMoving = Animator.StringToHash("isMoving");
|
||||
private static readonly int IsJumping = Animator.StringToHash("isJumping");
|
||||
private PlayerMove _player;
|
||||
|
||||
public IdleState(PlayerMove player)
|
||||
@@ -76,8 +78,8 @@ public class IdleState : IState
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
_player.Animator.SetBool("isMoving", false);
|
||||
_player.Animator.SetBool("isJumping", false);
|
||||
_player.Animator.SetBool(IsMoving, false);
|
||||
_player.Animator.SetBool(IsJumping, false);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@@ -90,15 +92,16 @@ public class IdleState : IState
|
||||
|
||||
public State CheckTransition()
|
||||
{
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
if (_player.Inputs.Jump)
|
||||
{
|
||||
return State.JUMP;
|
||||
}
|
||||
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0)
|
||||
// 수정: 좌우 어느 방향으로든 입력이 있을 때 MOVE 상태로 전환
|
||||
if (_player.Inputs.Move != Vector2.zero)
|
||||
{
|
||||
return State.MOVE;
|
||||
}
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (_player.Inputs.Attack)
|
||||
{
|
||||
return State.Attack;
|
||||
}
|
||||
@@ -108,6 +111,7 @@ public class IdleState : IState
|
||||
|
||||
public class MoveState : IState
|
||||
{
|
||||
private static readonly int IsMoving = Animator.StringToHash("isMoving");
|
||||
private PlayerMove _player;
|
||||
|
||||
public MoveState(PlayerMove player)
|
||||
@@ -117,23 +121,21 @@ public class MoveState : IState
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
_player.Animator.SetBool("isMoving", true);
|
||||
_player.Animator.SetBool(IsMoving, true);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
float horizontalInput = Input.GetAxisRaw("Horizontal");
|
||||
float horizontalInput = _player.Inputs.Move.x;
|
||||
if (horizontalInput != 0)
|
||||
{
|
||||
// transform.localScale.x를 사용하여 캐릭터와 자식 오브젝트를 함께 뒤집습니다.
|
||||
// 기본 스프라이트가 왼쪽을 바라보고 있으므로, 오른쪽 이동 시 x 스케일을 뒤집어야 합니다.
|
||||
Vector3 newScale = _player.transform.localScale;
|
||||
newScale.x = horizontalInput > 0 ? -1f : 1f;
|
||||
_player.transform.localScale = newScale;
|
||||
}
|
||||
|
||||
_player.RigidBody.AddForce(Vector2.right * horizontalInput * _player.maxSpeed, ForceMode2D.Force);
|
||||
|
||||
|
||||
if (Mathf.Abs(_player.RigidBody.linearVelocity.x) > _player.maxSpeed)
|
||||
{
|
||||
_player.RigidBody.linearVelocity = new Vector2(Mathf.Sign(_player.RigidBody.linearVelocity.x) * _player.maxSpeed, _player.RigidBody.linearVelocity.y);
|
||||
@@ -142,20 +144,20 @@ public class MoveState : IState
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_player.Animator.SetBool("isMoving", false);
|
||||
_player.Animator.SetBool(IsMoving, false);
|
||||
}
|
||||
|
||||
public State CheckTransition()
|
||||
{
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
if (_player.Inputs.Jump)
|
||||
{
|
||||
return State.JUMP;
|
||||
}
|
||||
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) < 0.1f)
|
||||
if (_player.Inputs.Move == Vector2.zero)
|
||||
{
|
||||
return State.IDLE;
|
||||
}
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (_player.Inputs.Attack)
|
||||
{
|
||||
return State.Attack;
|
||||
}
|
||||
@@ -165,6 +167,7 @@ public class MoveState : IState
|
||||
|
||||
public class JumpState : IState
|
||||
{
|
||||
private static readonly int IsJumping = Animator.StringToHash("isJumping");
|
||||
private PlayerMove _player;
|
||||
|
||||
public JumpState(PlayerMove player)
|
||||
@@ -175,27 +178,28 @@ public class JumpState : IState
|
||||
public void Enter()
|
||||
{
|
||||
_player.RigidBody.AddForce(Vector2.up * _player.jumpPower, ForceMode2D.Impulse);
|
||||
_player.Animator.SetBool("isJumping", true);
|
||||
_player.Animator.SetBool(IsJumping, true);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Input.GetButton("Horizontal"))
|
||||
float horizontalInput = _player.Inputs.Move.x;
|
||||
if (horizontalInput != 0)
|
||||
{
|
||||
Vector3 newScale = _player.transform.localScale;
|
||||
newScale.x = Input.GetAxisRaw("Horizontal") > 0 ? -1f : 1f;
|
||||
newScale.x = horizontalInput > 0 ? -1f : 1f;
|
||||
_player.transform.localScale = newScale;
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
_player.Animator.SetBool("isJumping", false);
|
||||
_player.Animator.SetBool(IsJumping, false);
|
||||
}
|
||||
|
||||
public State CheckTransition()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (_player.Inputs.Attack)
|
||||
{
|
||||
return State.Attack;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user