'유니티 회전'에 해당되는 글 2건

  1. 2014.08.04 C# Input.GetAxis ("Vertical") 와 transform.Rotate()
  2. 2014.08.04 C# 회전
Unity2014. 8. 4. 16:22

using UnityEngine;

using System.Collections;


public class Move2 : MonoBehaviour {


public float moveSpeed = 5f;

public float turnSpeed = 180f;


// 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 (0f, 0f, v * moveSpeed * Time.deltaTime));

transform.Rotate (0f, h * turnSpeed * Time.deltaTime, 0f);

}

}

'Unity' 카테고리의 다른 글

중력을 추가 Physics.gravity.y  (0) 2014.08.04
로컬좌표계에서 캐릭터 이동  (0) 2014.08.04
C# IInput.GetAxis ("Horizontal")와 transform.Translate()  (0) 2014.08.04
C# 회전  (0) 2014.08.04
C# 이동 Input.GetAxis ("Horizontal");  (0) 2014.08.04
Posted by 코드버무려
Unity2014. 8. 4. 15:51

유니티에서 방향키를 누르면 회전하면서 이동한다.


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);

}

}

Posted by 코드버무려