GAME/유니티

플레이어 설정

JC0 2022. 3. 10. 17:10

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);
        
    }
}