Unity/Team Project
프로젝트 1-1 플레이어 이동
Korokke
2022. 3. 15. 15:58
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float speed = 5f;
void Update()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Vector3 dir = Vector3.right * h + Vector3.up * v;
//dir의 크기가 1이 아닌 경우가 있음 -> 크기를 1로 만들 때 정규화
dir.Normalize();
transform.position += dir * speed * Time.deltaTime;
}
}