프로그래밍 정리/Unity

[Unity - 유니티] 전후좌우 이동방향 계산 및 이동

주누다 2014. 6. 1. 22:29
반응형

float h = 0.0f;

float v = 0.0f;


Transform thisTr;


float Speed = 15.0f;


void Start()

{

thisTr = GameObject.GetComponent<Transform>();

}


void Update()

{

h = Input.GetAxis("Horizontal");

v = Input.GetAxis("Vertical");


Vector3 moveDirection = (Vector3.forwad * v) + (Vector3.right * h);


thisTr.Translate(moveDirection * Time.deltaTime * Speed, Space.Self);

}



※ Space.Self = 로컬 좌표계

    Space.World = 월드 좌표계


반응형