반응형
// 캐릭터에서 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);
}
}
}
반응형
'Programing > unity' 카테고리의 다른 글
unity,유니티 ,마우스 이동 상하,방향으로 캐릭터 회전 (0) | 2017.02.25 |
---|---|
unity,유니티 ,마우스 이동 좌우,방향으로 캐릭터 회전 (1) | 2017.02.25 |
유니티 ,unity.캐릭터 따라다니는 카메라 (0) | 2017.02.25 |
유니티,unity,3d 캐릭터 클릭한 방향으로 회전하기 (0) | 2017.02.25 |
unity,유니티,3d 클릭시 이동,RaycastHit ,Raycast ,ScreenPointToRay (0) | 2017.02.25 |