[Unity] 플레이어 이동하기

Yerin·2023년 6월 12일
0

너무나도 극단적인 이동.. ㅋㅋㅋㅋㅋㅋ

이번 강의에서 알게된 점

  • 키보드 입력 받기
  • 직관적인 캐릭터 위치 변경
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerContoller : MonoBehaviour
{
    
    void Start()
    {
        
    }

    
    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);
        //transform
    }
}
profile
재밌는 코딩 공부

0개의 댓글