캐릭터 점프 및 이동 코드 수정
This commit is contained in:
@@ -33,7 +33,7 @@ AnimatorStateMachine:
|
|||||||
m_ChildStates:
|
m_ChildStates:
|
||||||
- serializedVersion: 1
|
- serializedVersion: 1
|
||||||
m_State: {fileID: 2757263598689776561}
|
m_State: {fileID: 2757263598689776561}
|
||||||
m_Position: {x: 270, y: 60, z: 0}
|
m_Position: {x: 320, y: 110, z: 0}
|
||||||
m_ChildStateMachines: []
|
m_ChildStateMachines: []
|
||||||
m_AnyStateTransitions: []
|
m_AnyStateTransitions: []
|
||||||
m_EntryTransitions: []
|
m_EntryTransitions: []
|
||||||
@@ -51,7 +51,7 @@ AnimatorState:
|
|||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_Name: 1New Animation
|
m_Name: Idle
|
||||||
m_Speed: 1
|
m_Speed: 1
|
||||||
m_CycleOffset: 0
|
m_CycleOffset: 0
|
||||||
m_Transitions: []
|
m_Transitions: []
|
||||||
|
|||||||
@@ -954,7 +954,7 @@ Transform:
|
|||||||
m_GameObject: {fileID: 313304219}
|
m_GameObject: {fileID: 313304219}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
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_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
@@ -1014,7 +1014,7 @@ Rigidbody2D:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 313304219}
|
m_GameObject: {fileID: 313304219}
|
||||||
m_BodyType: 0
|
m_BodyType: 2
|
||||||
m_Simulated: 1
|
m_Simulated: 1
|
||||||
m_UseFullKinematicContacts: 0
|
m_UseFullKinematicContacts: 0
|
||||||
m_UseAutoMass: 0
|
m_UseAutoMass: 0
|
||||||
@@ -1329,7 +1329,7 @@ GameObject:
|
|||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 0
|
||||||
--- !u!4 &749815948
|
--- !u!4 &749815948
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -2526,6 +2526,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
maxSpeed: 5
|
maxSpeed: 5
|
||||||
|
jumpPower: 10
|
||||||
--- !u!1 &1133366865
|
--- !u!1 &1133366865
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 0ea3e7753e5fb28479a6f577e4b35668
|
|
||||||
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 72ed9ef5cc3e0834b911c392c618dccd
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
59
Assets/Scripts/Player/PlayerMove.cs
Normal file
59
Assets/Scripts/Player/PlayerMove.cs
Normal file
@@ -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<Rigidbody2D>();
|
||||||
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||||
|
animator = GetComponent<Animator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Player/PlayerMove.cs.meta
Normal file
2
Assets/Scripts/Player/PlayerMove.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0371ecf29219fdd45a4b084bb00968b3
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class PlayerController : MonoBehaviour
|
|
||||||
{
|
|
||||||
private Movement2D movement2D;
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
movement2D = GetComponent<Movement2D>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
float x = Input.GetAxis("Horizontal");
|
|
||||||
float y = Input.GetAxis("Vertical");
|
|
||||||
|
|
||||||
movement2D.MoveDirection = new Vector2(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 7faac9c66ceb4b342b90f97ea09a456c
|
|
||||||
Reference in New Issue
Block a user