랭귀지/Unity
유니티 케릭터 이동 Transform Translate
유키공
2018. 3. 18. 09:30
유니티로 게임을 개발시 해당키를 눌렀을때 일정범위 만큼 움직여야 할 경우 Translate 함수를 사용합니다.
간단한 예제입니다.
void Update () {
if (Input.GetKey (KeyCode.LeftArrow) == true) {
this.GetComponent<Transform> ().Translate (-0.05f, 0, 0);
}
if (Input.GetKey (KeyCode.RightArrow) == true) {
this.GetComponent<Transform> ().Translate (0.05f, 0, 0);
}
if (Input.GetKey (KeyCode.UpArrow) == true) {
this.GetComponent<Transform> ().Translate (0, 0.05f, 0);
}
if (Input.GetKey (KeyCode.DownArrow) == true) {
this.GetComponent<Transform> ().Translate (0, -0.05f, 0);
}
}