PlayerController 스크립트를 작성하고 임포트한 에셋의 컴포넌트로 추가해주면 캐릭터의 위치값을 변경할 수 있다.
using UnityEngine;
public class PlayerController : MonoBehaviour
{
void Start()
{
}
// GameObject(Player)
//Transform
//PlayerController
void Update()
{
if (Input.GetKey(KeyCode.W))
transform.position += new Vector3(0.0f, 0.0f, 1.0f);
if (Input.GetKey(KeyCode.S))
transform.position += new Vector3(0.0f, 0.0f, -1.0f);
if (Input.GetKey(KeyCode.A))
transform.position += new Vector3(1.0f, 0.0f, 0.0f);
if (Input.GetKey(KeyCode.D))
transform.position += new Vector3(-1.0f, 0.0f, 0.0f);
}
}
'GAME > 유니티' 카테고리의 다른 글
컴포넌트 패턴 (0) | 2022.03.04 |
---|---|
Instantiate() 메소드 (0) | 2021.06.01 |
왼쪽 마우스 버튼을 눌렀을때 색 변화시키기 (0) | 2021.05.27 |
1.유니티 시작하기 (0) | 2021.05.26 |