diff --git a/Assets/Scripts/Player/PlayerMove.cs b/Assets/Scripts/Player/PlayerMove.cs index 275fe3d0..f106d340 100644 --- a/Assets/Scripts/Player/PlayerMove.cs +++ b/Assets/Scripts/Player/PlayerMove.cs @@ -4,11 +4,6 @@ using UnityEngine.InputSystem; public class PlayerMove : MonoBehaviour { - [SerializeField] - float speed; - float inputValue; - - public float maxSpeed; public float jumpPower; Rigidbody2D rigidBody; @@ -27,52 +22,39 @@ public class PlayerMove : MonoBehaviour private void Update() { - // // 점프 - // if (Input.GetButtonDown("Jump")) - // { - // rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse); - // } - // - // // 키 입력 땔때 캐릭터 멈춤 - // if (Input.GetButtonUp("Horizontal")) - // { - // rigidBody.linearVelocity = new Vector2(rigidBody.linearVelocity.normalized.x * 0.0000001f, rigidBody.linearVelocity.y); - // } - // - // // 캐릭터(Sprite)이동 방향 바라보도록 스프라이트 플립 - // if (Input.GetButton("Horizontal")) - // { - // spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1; - // } + // 점프 + if (Input.GetButtonDown("Jump")) + { + rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse); + } + + // 키 입력 땔때 캐릭터 멈춤 + if (Input.GetButtonUp("Horizontal")) + { + rigidBody.linearVelocity = new Vector2(rigidBody.linearVelocity.normalized.x * 0.0000001f, rigidBody.linearVelocity.y); + } + + // 캐릭터(Sprite)이동 방향 바라보도록 스프라이트 플립 + if (Input.GetButton("Horizontal")) + { + spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1; + } } void FixedUpdate() { - // // 캐릭터 움직임 컨트롤 - // float h = Input.GetAxisRaw("Horizontal"); - // rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse); + // 캐릭터 움직임 컨트롤 + float h = Input.GetAxisRaw("Horizontal"); + rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse); - rigidBody.linearVelocityX = inputValue * speed; - - // - // // 유니티6 부터 Velocity에서 LinearVelocity로 변경 - // if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도 - // { - // rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y); - // } - // else if (rigidBody.linearVelocity.x < maxSpeed * (-1)) - // { - // rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), rigidBody.linearVelocity.y); - // } - } - - private void OnMove(InputValue value) - { - inputValue = value.Get().x; - } - - private void OnJump() - { - rigidBody.AddForceY(jumpPower, ForceMode2D.Impulse); + // 유니티6 부터 Velocity에서 LinearVelocity로 변경 + if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도 + { + rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y); + } + else if (rigidBody.linearVelocity.x < maxSpeed * (-1)) + { + rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), rigidBody.linearVelocity.y); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Player/PlayerMove2.cs b/Assets/Scripts/Player/PlayerMove2.cs new file mode 100644 index 00000000..7f9f9df9 --- /dev/null +++ b/Assets/Scripts/Player/PlayerMove2.cs @@ -0,0 +1,45 @@ +using System; +using UnityEngine; +using UnityEngine.InputSystem; + +public class PlayerMove2 : MonoBehaviour +{ + [SerializeField] + float speed; + [SerializeField] + float jumpPower; + float inputValue; + + + Rigidbody2D rigidBody; + SpriteRenderer spriteRenderer; + // TODO : 걷기, 점프 등 애니메이션 + Animator animator; + + void Awake() + { + rigidBody = GetComponent(); + spriteRenderer = GetComponent(); + animator = GetComponent(); + } + + void FixedUpdate() + { + rigidBody.linearVelocityX = inputValue * speed; + } + + void LateUpdate() + { + + } + + private void OnMove(InputValue value) + { + inputValue = value.Get().x; + } + + private void OnJump() + { + rigidBody.AddForceY(jumpPower, ForceMode2D.Impulse); + } +} diff --git a/Assets/Scripts/Player/PlayerMove2.cs.meta b/Assets/Scripts/Player/PlayerMove2.cs.meta new file mode 100644 index 00000000..e46ab6fe --- /dev/null +++ b/Assets/Scripts/Player/PlayerMove2.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7f6c7bf7168cf414f9961139d84eb992 \ No newline at end of file