코드 정리하여 PlayerMove2로 분리

This commit is contained in:
Mingu Kim
2025-07-09 23:06:26 +09:00
parent ad2125fc1e
commit 97a96b503d
3 changed files with 76 additions and 47 deletions

View 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);
}
}