코드 정리하여 PlayerMove2로 분리
This commit is contained in:
@@ -4,11 +4,6 @@ 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;
|
||||||
@@ -27,52 +22,39 @@ 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);
|
||||||
|
|
||||||
rigidBody.linearVelocityX = inputValue * speed;
|
// 유니티6 부터 Velocity에서 LinearVelocity로 변경
|
||||||
|
if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
||||||
//
|
|
||||||
// // 유니티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<Vector2>().x;
|
rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y);
|
||||||
}
|
}
|
||||||
|
else if (rigidBody.linearVelocity.x < maxSpeed * (-1))
|
||||||
private void OnJump()
|
|
||||||
{
|
{
|
||||||
rigidBody.AddForceY(jumpPower, ForceMode2D.Impulse);
|
rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), rigidBody.linearVelocity.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
Assets/Scripts/Player/PlayerMove2.cs
Normal file
45
Assets/Scripts/Player/PlayerMove2.cs
Normal file
@@ -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<Rigidbody2D>();
|
||||||
|
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||||
|
animator = GetComponent<Animator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
rigidBody.linearVelocityX = inputValue * speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LateUpdate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMove(InputValue value)
|
||||||
|
{
|
||||||
|
inputValue = value.Get<Vector2>().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnJump()
|
||||||
|
{
|
||||||
|
rigidBody.AddForceY(jumpPower, ForceMode2D.Impulse);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Player/PlayerMove2.cs.meta
Normal file
2
Assets/Scripts/Player/PlayerMove2.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7f6c7bf7168cf414f9961139d84eb992
|
||||||
Reference in New Issue
Block a user