Translate 및 Rotate

Tutorial

Beginner

+10XP

5 mins

(43)

Unity Technologies

Translate 및 Rotate

두 가지 트랜스폼 함수인 Translate와 Rotate를 사용하여 리지드바디가 아닌 오브젝트의 위치와 회전을 변경하는 방법을 알아봅니다.

이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.

이전: 게임 오브젝트 활성화

다음: LookAt

1. Translate 및 Rotate

TransformFunctions

using UnityEngine;
using System.Collections;

public class TransformFunctions : MonoBehaviour
{
    public float moveSpeed = 10f;
    public float turnSpeed = 50f;
    
    
    void Update ()
    {
        if(Input.GetKey(KeyCode.UpArrow))
            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
        
        if(Input.GetKey(KeyCode.DownArrow))
            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
        
        if(Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
        
        if(Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    }
}

Complete this Tutorial