유니티3D/예제

자동차 좌우 이동

당꿈응 2013. 7. 22. 14:28

 

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
 
 public float Speed = 10.0f;
 // Use this for initialization
 void Start () {
  
 }
 
 // Update is called once per frame
 void Update () {
  float h = Input.GetAxis("Horizontal");    //input ->  입력  좌우로 움직이는 명령어Time.deltaTime.
  float v = Input.GetAxis("Vertical");
  
  transform.Translate(Vector3.right * h * Speed *Time.deltaTime);     

 //왼쪽으로 움직이면 음수값이 나오기 때문에 left는 따로 적을필요 없다.
  transform.Translate(Vector3.up * v * Speed *Time.deltaTime);
  
 }