본문 바로가기
Programing/unity

유니티,unity, CharacterController 를 이용한 캐릭터이동

by 고니피즈 2017. 2. 25.
반응형

// 캐릭터에서 Character Controller 콤포넌트 추가하고 ,Character 에 이 스크립트 바인딩하고 


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Move : MonoBehaviour {


public CharacterController CC; // 인스펙트 창에 뜨는 빈칸에  위의 Character Controlle 콤포넌트 드래그해서 넣어줍니다.

float movespeed=5f;



void Start () {

}


void Update () {

if(Input.GetKey(KeyCode.W)){  // w 키를 누르면 z 축으로 이동

CC.Move (transform.forward * movespeed * Time.deltaTime);

}

if(Input.GetKey(KeyCode.S)){

CC.Move (transform.forward* -1f * movespeed * Time.deltaTime);

}

if(Input.GetKey(KeyCode.A)){

CC.Move (transform.right* -1f * movespeed * Time.deltaTime);

}

if(Input.GetKey(KeyCode.D)){

CC.Move (transform.right * movespeed * Time.deltaTime);

}

}

}



반응형