캐릭터 이동 코드 구현
This commit is contained in:
14
Assets/Scripts/Movement2D.cs
Normal file
14
Assets/Scripts/Movement2D.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Movement2D.cs.meta
Normal file
2
Assets/Scripts/Movement2D.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ea3e7753e5fb28479a6f577e4b35668
|
||||
19
Assets/Scripts/PlayerController.cs
Normal file
19
Assets/Scripts/PlayerController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayerController.cs.meta
Normal file
2
Assets/Scripts/PlayerController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7faac9c66ceb4b342b90f97ea09a456c
|
||||
Reference in New Issue
Block a user