unity6에서 변경된 linearVelocityX, AddForceY와 같이 x축, y축으로 나눠진 함수 사용
This commit is contained in:
@@ -2356,7 +2356,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_Actions: {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3}
|
m_Actions: {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3}
|
||||||
m_NotificationBehavior: 2
|
m_NotificationBehavior: 0
|
||||||
m_UIInputModule: {fileID: 0}
|
m_UIInputModule: {fileID: 0}
|
||||||
m_DeviceLostEvent:
|
m_DeviceLostEvent:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
@@ -2367,83 +2367,7 @@ MonoBehaviour:
|
|||||||
m_ControlsChangedEvent:
|
m_ControlsChangedEvent:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
m_ActionEvents:
|
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_NeverAutoSwitchControlSchemes: 0
|
m_NeverAutoSwitchControlSchemes: 0
|
||||||
m_DefaultControlScheme:
|
m_DefaultControlScheme:
|
||||||
m_DefaultActionMap: Player
|
m_DefaultActionMap: Player
|
||||||
@@ -2525,6 +2449,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 0371ecf29219fdd45a4b084bb00968b3, type: 3}
|
m_Script: {fileID: 11500000, guid: 0371ecf29219fdd45a4b084bb00968b3, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
speed: 3
|
||||||
maxSpeed: 5
|
maxSpeed: 5
|
||||||
jumpPower: 10
|
jumpPower: 10
|
||||||
--- !u!1 &1133366865
|
--- !u!1 &1133366865
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
public class PlayerMove : MonoBehaviour
|
public class PlayerMove : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[SerializeField]
|
||||||
|
float speed;
|
||||||
|
float inputValue;
|
||||||
|
|
||||||
|
|
||||||
public float maxSpeed;
|
public float maxSpeed;
|
||||||
public float jumpPower;
|
public float jumpPower;
|
||||||
Rigidbody2D rigidBody;
|
Rigidbody2D rigidBody;
|
||||||
@@ -21,39 +27,52 @@ public class PlayerMove : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
// 점프
|
// // 점프
|
||||||
if (Input.GetButtonDown("Jump"))
|
// if (Input.GetButtonDown("Jump"))
|
||||||
{
|
// {
|
||||||
rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
|
// rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 키 입력 땔때 캐릭터 멈춤
|
// // 키 입력 땔때 캐릭터 멈춤
|
||||||
if (Input.GetButtonUp("Horizontal"))
|
// if (Input.GetButtonUp("Horizontal"))
|
||||||
{
|
// {
|
||||||
rigidBody.linearVelocity = new Vector2(rigidBody.linearVelocity.normalized.x * 0.0000001f, rigidBody.linearVelocity.y);
|
// rigidBody.linearVelocity = new Vector2(rigidBody.linearVelocity.normalized.x * 0.0000001f, rigidBody.linearVelocity.y);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 캐릭터(Sprite)이동 방향 바라보도록 스프라이트 플립
|
// // 캐릭터(Sprite)이동 방향 바라보도록 스프라이트 플립
|
||||||
if (Input.GetButton("Horizontal"))
|
// if (Input.GetButton("Horizontal"))
|
||||||
{
|
// {
|
||||||
spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1;
|
// spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
// 캐릭터 움직임 컨트롤
|
// // 캐릭터 움직임 컨트롤
|
||||||
float h = Input.GetAxisRaw("Horizontal");
|
// float h = Input.GetAxisRaw("Horizontal");
|
||||||
rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
|
// rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
|
||||||
|
|
||||||
// 유니티6 부터 Velocity에서 LinearVelocity로 변경
|
rigidBody.linearVelocityX = inputValue * speed;
|
||||||
if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
|
||||||
{
|
//
|
||||||
rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y);
|
// // 유니티6 부터 Velocity에서 LinearVelocity로 변경
|
||||||
}
|
// if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
||||||
else if (rigidBody.linearVelocity.x < maxSpeed * (-1))
|
// {
|
||||||
{
|
// rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y);
|
||||||
rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), 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<Vector2>().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnJump()
|
||||||
|
{
|
||||||
|
rigidBody.AddForceY(jumpPower, ForceMode2D.Impulse);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user