각 상태를 담을 수 있는 딕셔너리에 상태 저장하도록 구조 수정
This commit is contained in:
@@ -8,13 +8,6 @@ public class PlayerMove : MonoBehaviour
|
||||
public SpriteRenderer SpriteRenderer { get; private set; }
|
||||
public Animator Animator { get; private set; }
|
||||
|
||||
// 다른 클래스에서 접근할 수 있도록 private static 변수와 public 프로퍼티를 분리
|
||||
private static int _isJumping;
|
||||
private static int _isMoving;
|
||||
|
||||
public static int IsJumping => _isJumping;
|
||||
public static int IsMoving => _isMoving;
|
||||
|
||||
public float maxSpeed;
|
||||
public float jumpPower;
|
||||
|
||||
@@ -41,11 +34,7 @@ public class PlayerMove : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Animator가 초기화된 후에 해시 값 할당
|
||||
_isJumping = Animator.StringToHash("isJumping");
|
||||
_isMoving = Animator.StringToHash("isMoving");
|
||||
|
||||
_stateMachine = new StateMachine(new IdleState(this));
|
||||
_stateMachine = new StateMachine(State.IDLE, this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -55,7 +44,17 @@ public class PlayerMove : MonoBehaviour
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
_stateMachine.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);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
|
||||
Reference in New Issue
Block a user