플레이어 조작 코드 수정
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
public float maxSpeed;
|
||||
public float jumpPower;
|
||||
Rigidbody2D rigidBody;
|
||||
SpriteRenderer spriteRenderer;
|
||||
Rigidbody2D _rigidBody;
|
||||
SpriteRenderer _spriteRenderer;
|
||||
|
||||
// TODO : 걷기, 점프 등 애니메이션
|
||||
Animator animator;
|
||||
// TODO : 점프, 공격, 돌진, 슈퍼 대시
|
||||
Animator _animator;
|
||||
|
||||
// 변수
|
||||
[SerializeField]
|
||||
public int hp = 5;
|
||||
|
||||
// 사용하는 컴포넌트들 초기화
|
||||
void Awake()
|
||||
{
|
||||
rigidBody = GetComponent<Rigidbody2D>();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
animator = GetComponent<Animator>();
|
||||
_rigidBody = GetComponent<Rigidbody2D>();
|
||||
_spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -25,19 +26,19 @@ public class PlayerMove : MonoBehaviour
|
||||
// 점프
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
{
|
||||
rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
|
||||
_rigidBody.AddForce(Vector2.up * jumpPower, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
// 키 입력 땔때 캐릭터 멈춤
|
||||
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)이동 방향 바라보도록 스프라이트 플립
|
||||
if (Input.GetButton("Horizontal"))
|
||||
{
|
||||
spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1;
|
||||
_spriteRenderer.flipX = Input.GetAxisRaw("Horizontal") >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,16 +46,16 @@ public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
// 캐릭터 움직임 컨트롤
|
||||
float h = Input.GetAxisRaw("Horizontal");
|
||||
rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
|
||||
_rigidBody.AddForce(Vector2.right * h, ForceMode2D.Impulse);
|
||||
|
||||
// 유니티6 부터 Velocity에서 LinearVelocity로 변경
|
||||
if (rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
||||
if (_rigidBody.linearVelocity.x > maxSpeed) // 오른쪽 최대 속도
|
||||
{
|
||||
rigidBody.linearVelocity = new Vector2(maxSpeed, rigidBody.linearVelocity.y);
|
||||
_rigidBody.linearVelocity = new Vector2(maxSpeed, _rigidBody.linearVelocity.y);
|
||||
}
|
||||
else if (rigidBody.linearVelocity.x < maxSpeed * (-1))
|
||||
else if (_rigidBody.linearVelocity.x < maxSpeed * (-1))
|
||||
{
|
||||
rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), rigidBody.linearVelocity.y);
|
||||
_rigidBody.linearVelocity = new Vector2(maxSpeed * (-1), _rigidBody.linearVelocity.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user