
SampleScene 아래에는 Main Camera, Directional Light, 그리고 Player라는 객체가 있습니다.Transform 컴포넌트를 포함하고 있으며, 작성한 PlayerController 스크립트가 연결되어 있습니다.Player 오브젝트의 Transform 컴포넌트는 위치(Position), 회전(Rotation), 스케일(Scale)을 정의합니다.Animator 컴포넌트가 추가되어 있으며, 캐릭터 애니메이션 동작을 제어할 수 있습니다.PlayerController를 통해 캐릭터의 동작을 제어합니다.Animations, Art, Models 등 여러 폴더 구조가 있습니다. UnityChan 관련 데이터가 Materials, Models, Textures로 나뉘어 관리되고 있습니다.PlayerController.cs 스크립트가 포함되어 있습니다.public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
// 게임 시작 시 한 번 실행되는 초기화 메서드
}
// Update is called once per frame
void Update()
{
// 키보드 입력에 따라 캐릭터 이동
if (Input.GetKey(KeyCode.W)) // 'W' 키가 눌리면
{
transform.position += new Vector3(0.0f, 0.0f, 1.0f); // 캐릭터가 z축 방향으로 이동
}
if (Input.GetKey(KeyCode.S)) // 'S' 키가 눌리면
{
transform.position -= new Vector3(0.0f, 0.0f, 1.0f); // 캐릭터가 z축 반대 방향으로 이동
}
if (Input.GetKey(KeyCode.A)) // 'A' 키가 눌리면
{
transform.position -= new Vector3(1.0f, 0.0f, 0.0f); // 캐릭터가 x축 반대 방향으로 이동
}
if (Input.GetKey(KeyCode.D)) // 'D' 키가 눌리면
{
transform.position += new Vector3(1.0f, 0.0f, 0.0f); // 캐릭터가 x축 방향으로 이동
}
}
}
클래스 상속:
PlayerController는 MonoBehaviour를 상속받아 Unity의 게임 오브젝트 스크립트로 동작합니다.Start 메서드:
Update 메서드:
키 입력과 이동 로직:
Input.GetKey(KeyCode.X)를 사용해 특정 키보드 입력을 감지합니다.transform.position을 직접 수정해 캐릭터를 이동시킵니다.W 키 입력 시 z축 양의 방향으로 이동.W, A, S, D)에 맞게 Vector3를 더하거나 뺍니다.