diff --git a/Assets/Art/Animation/KnightAnimatorController.controller b/Assets/Art/Animation/KnightAnimatorController.controller index 9e1ad574..a219db31 100644 --- a/Assets/Art/Animation/KnightAnimatorController.controller +++ b/Assets/Art/Animation/KnightAnimatorController.controller @@ -33,7 +33,7 @@ AnimatorStateMachine: m_ChildStates: - serializedVersion: 1 m_State: {fileID: 2757263598689776561} - m_Position: {x: 270, y: 60, z: 0} + m_Position: {x: 320, y: 110, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: [] m_EntryTransitions: [] @@ -51,7 +51,7 @@ AnimatorState: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: 1New Animation + m_Name: Idle m_Speed: 1 m_CycleOffset: 0 m_Transitions: [] diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index ab3c693f..b82a89fe 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -954,7 +954,7 @@ Transform: m_GameObject: {fileID: 313304219} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 3.337, y: -3.938, z: 0} + m_LocalPosition: {x: 3.567, y: -2.683, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1014,7 +1014,7 @@ Rigidbody2D: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 313304219} - m_BodyType: 0 + m_BodyType: 2 m_Simulated: 1 m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 @@ -1329,7 +1329,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &749815948 Transform: m_ObjectHideFlags: 0 @@ -2526,6 +2526,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: maxSpeed: 5 + jumpPower: 10 --- !u!1 &1133366865 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Movement2D.cs b/Assets/Scripts/Movement2D.cs deleted file mode 100644 index 919a136e..00000000 --- a/Assets/Scripts/Movement2D.cs +++ /dev/null @@ -1,14 +0,0 @@ -using UnityEngine; - -public class Movement2D : MonoBehaviour -{ - [SerializeField] - private float moveSpeed = 5f; - - public Vector3 MoveDirection { get; set; } = Vector2.zero; - - private void Update() - { - transform.position += MoveDirection * moveSpeed * Time.deltaTime; - } -} diff --git a/Assets/Scripts/Movement2D.cs.meta b/Assets/Scripts/Movement2D.cs.meta deleted file mode 100644 index 510fdb63..00000000 --- a/Assets/Scripts/Movement2D.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 0ea3e7753e5fb28479a6f577e4b35668 \ No newline at end of file diff --git a/Assets/Scripts/Player.meta b/Assets/Scripts/Player.meta new file mode 100644 index 00000000..8f28d31c --- /dev/null +++ b/Assets/Scripts/Player.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 72ed9ef5cc3e0834b911c392c618dccd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerMove.cs b/Assets/Scripts/Player/PlayerMove.cs new file mode 100644 index 00000000..c87e5421 --- /dev/null +++ b/Assets/Scripts/Player/PlayerMove.cs @@ -0,0 +1,59 @@ +using System; +using UnityEngine; + +public class PlayerMove : MonoBehaviour +{ + public float maxSpeed; + public float jumpPower; + Rigidbody2D rigidBody; + SpriteRenderer spriteRenderer; + + // TODO : 걷기, 점프 등 애니메이션 + Animator animator; + + // 사용하는 컴포넌트들 초기화 + void Awake() + { + rigidBody = GetComponent(); + spriteRenderer = GetComponent(); + animator = GetComponent(); + } + + 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.5f, rigidBody.linearVelocity.y); + } + + // 캐릭터(Sprite) 방향 + if (Input.GetButtonDown("Horizontal")) + { + spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1; + } + } + + void FixedUpdate() + { + // 캐릭터 움직임 컨트롤 + 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); + } + } +} diff --git a/Assets/Scripts/Player/PlayerMove.cs.meta b/Assets/Scripts/Player/PlayerMove.cs.meta new file mode 100644 index 00000000..93b33640 --- /dev/null +++ b/Assets/Scripts/Player/PlayerMove.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0371ecf29219fdd45a4b084bb00968b3 \ No newline at end of file diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs deleted file mode 100644 index b5cf6d39..00000000 --- a/Assets/Scripts/PlayerController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using UnityEngine; - -public class PlayerController : MonoBehaviour -{ - private Movement2D movement2D; - - private void Awake() - { - movement2D = GetComponent(); - } - - private void Update() - { - float x = Input.GetAxis("Horizontal"); - float y = Input.GetAxis("Vertical"); - - movement2D.MoveDirection = new Vector2(x, y); - } -} diff --git a/Assets/Scripts/PlayerController.cs.meta b/Assets/Scripts/PlayerController.cs.meta deleted file mode 100644 index 55fb6b41..00000000 --- a/Assets/Scripts/PlayerController.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 7faac9c66ceb4b342b90f97ea09a456c \ No newline at end of file