From ad2125fc1e0feb84613a4306efa4cebe86e7e157 Mon Sep 17 00:00:00 2001 From: mingu Date: Wed, 9 Jul 2025 19:57:46 +0900 Subject: [PATCH] =?UTF-8?q?unity6=EC=97=90=EC=84=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EB=90=9C=20linearVelocityX,=20AddForceY=EC=99=80=20=EA=B0=99?= =?UTF-8?q?=EC=9D=B4=20x=EC=B6=95,=20y=EC=B6=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=82=98=EB=88=A0=EC=A7=84=20=ED=95=A8=EC=88=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/SampleScene.unity | 81 ++--------------------------- Assets/Scripts/Player/PlayerMove.cs | 79 +++++++++++++++++----------- 2 files changed, 52 insertions(+), 108 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b82a89fe..c5872b3b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2356,7 +2356,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Actions: {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3} - m_NotificationBehavior: 2 + m_NotificationBehavior: 0 m_UIInputModule: {fileID: 0} m_DeviceLostEvent: m_PersistentCalls: @@ -2367,83 +2367,7 @@ MonoBehaviour: m_ControlsChangedEvent: m_PersistentCalls: m_Calls: [] - m_ActionEvents: - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 351f2ccd-1f9f-44bf-9bec-d62ac5c5f408 - m_ActionName: 'Player/Move[/DualSenseGamepadHID/leftStick,/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 6b444451-8a00-4d00-a97e-f47457f736a8 - m_ActionName: 'Player/Look[/DualSenseGamepadHID/rightStick,/Mouse/delta]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 6c2ab1b8-8984-453a-af3d-a3c78ae1679a - m_ActionName: 'Player/Attack[/DualSenseGamepadHID/buttonWest,/Mouse/leftButton,/Keyboard/enter]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 852140f2-7766-474d-8707-702459ba45f3 - m_ActionName: 'Player/Interact[/Keyboard/e,/DualSenseGamepadHID/buttonNorth]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 27c5f898-bc57-4ee1-8800-db469aca5fe3 - m_ActionName: 'Player/Crouch[/DualSenseGamepadHID/buttonEast,/Keyboard/c]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: f1ba0d36-48eb-4cd5-b651-1c94a6531f70 - m_ActionName: 'Player/Jump[/Keyboard/space,/DualSenseGamepadHID/buttonSouth]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 2776c80d-3c14-4091-8c56-d04ced07a2b0 - m_ActionName: 'Player/Previous[/Keyboard/1,/DualSenseGamepadHID/dpad/left]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: b7230bb6-fc9b-4f52-8b25-f5e19cb2c2ba - m_ActionName: 'Player/Next[/Keyboard/2,/DualSenseGamepadHID/dpad/right]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 641cd816-40e6-41b4-8c3d-04687c349290 - m_ActionName: 'Player/Sprint[/Keyboard/leftShift,/DualSenseGamepadHID/leftStickPress]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: c95b2375-e6d9-4b88-9c4c-c5e76515df4b - m_ActionName: 'UI/Navigate[/DualSenseGamepadHID/leftStick/up,/DualSenseGamepadHID/rightStick/up,/DualSenseGamepadHID/leftStick/down,/DualSenseGamepadHID/rightStick/down,/DualSenseGamepadHID/leftStick/left,/DualSenseGamepadHID/rightStick/left,/DualSenseGamepadHID/leftStick/right,/DualSenseGamepadHID/rightStick/right,/DualSenseGamepadHID/dpad,/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 7607c7b6-cd76-4816-beef-bd0341cfe950 - m_ActionName: 'UI/Submit[/Keyboard/enter,/DualSenseGamepadHID/buttonSouth]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 15cef263-9014-4fd5-94d9-4e4a6234a6ef - m_ActionName: 'UI/Cancel[/Keyboard/escape,/DualSenseGamepadHID/buttonEast]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 32b35790-4ed0-4e9a-aa41-69ac6d629449 - m_ActionName: 'UI/Point[/Mouse/position]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 3c7022bf-7922-4f7c-a998-c437916075ad - m_ActionName: 'UI/Click[/Mouse/leftButton]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 44b200b1-1557-4083-816c-b22cbdf77ddf - m_ActionName: 'UI/RightClick[/Mouse/rightButton]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: dad70c86-b58c-4b17-88ad-f5e53adf419e - m_ActionName: 'UI/MiddleClick[/Mouse/middleButton]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 0489e84a-4833-4c40-bfae-cea84b696689 - m_ActionName: 'UI/ScrollWheel[/Mouse/scroll]' - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 24908448-c609-4bc3-a128-ea258674378a - m_ActionName: UI/TrackedDevicePosition - - m_PersistentCalls: - m_Calls: [] - m_ActionId: 9caa3d8a-6b2f-4e8e-8bad-6ede561bd9be - m_ActionName: UI/TrackedDeviceOrientation + m_ActionEvents: [] m_NeverAutoSwitchControlSchemes: 0 m_DefaultControlScheme: m_DefaultActionMap: Player @@ -2525,6 +2449,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0371ecf29219fdd45a4b084bb00968b3, type: 3} m_Name: m_EditorClassIdentifier: + speed: 3 maxSpeed: 5 jumpPower: 10 --- !u!1 &1133366865 diff --git a/Assets/Scripts/Player/PlayerMove.cs b/Assets/Scripts/Player/PlayerMove.cs index f3eab94d..275fe3d0 100644 --- a/Assets/Scripts/Player/PlayerMove.cs +++ b/Assets/Scripts/Player/PlayerMove.cs @@ -1,8 +1,14 @@ using System; using UnityEngine; +using UnityEngine.InputSystem; public class PlayerMove : MonoBehaviour { + [SerializeField] + float speed; + float inputValue; + + public float maxSpeed; public float jumpPower; Rigidbody2D rigidBody; @@ -21,39 +27,52 @@ 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); - // 유니티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); - } + 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); + } +} \ No newline at end of file