유니티에서 방향키를 누르면 회전하면서 이동한다.
using UnityEngine;
using System.Collections;
public class Move : MonoBehaviour {
public float moveSpeed;
public float turnSpeed = 90f; // 90도
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis ("Horizontal");
float v = Input.GetAxis ("Vertical");
transform.Translate (new Vector3 (h, v, 0f) * moveSpeed * Time.deltaTime);
transform.Rotate(0f, turnSpeed * Time.deltaTime, 0f);
}
}
'Unity' 카테고리의 다른 글
C# Input.GetAxis ("Vertical") 와 transform.Rotate() (0) | 2014.08.04 |
---|---|
C# IInput.GetAxis ("Horizontal")와 transform.Translate() (0) | 2014.08.04 |
C# 이동 Input.GetAxis ("Horizontal"); (0) | 2014.08.04 |
C# Scrip on Unity (0) | 2014.08.04 |
폴더 구조와 특성 (0) | 2014.08.04 |