[출처] https://itmining.tistory.com                                                                   https://m.blog.naver.com/hayandoud

 

[유니티 트랜스폼] 회전 (Rotate)

이 글은 PC 버전 TISTORY에 최적화 되어있습니다. 서론 3D 게임에서 회전이라는 요소는 굉장히 중요합니다. 앞만 보고 달리는 오버워치 캐릭터를 생각해보면 아찔합니다. 이번에는 마우스의 좌, 우 움직임에 따라..

itmining.tistory.com

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveObject : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
        moveObjectFunc();
    }


    private float speed_move = 3.0f;
    private float speed_rota = 2.0f;

    void moveObjectFunc()
    {
        float keyH = Input.GetAxis("Horizontal");
        float keyV = Input.GetAxis("Vertical");
        keyH = keyH * speed_move * Time.deltaTime;
        keyV = keyV * speed_move * Time.deltaTime;
        transform.Translate(Vector3.right * keyH);
        transform.Translate(Vector3.forward * keyV);

        float mouseX = Input.GetAxis("Mouse X");
        float mouseY = Input.GetAxis("Mouse Y");
        transform.Rotate(Vector3.up * speed_rota * mouseX);
        transform.Rotate(Vector3.left * speed_rota * mouseY);
    }
}

+ Recent posts