캐릭터 이동 코드 구현

This commit is contained in:
Mingu Kim
2025-06-05 03:21:27 +09:00
parent 51367624c1
commit 98597d1053
4 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
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;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0ea3e7753e5fb28479a6f577e4b35668

View File

@@ -0,0 +1,19 @@
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);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7faac9c66ceb4b342b90f97ea09a456c