본문 바로가기
유니티강좌

오브젝트(2D 캐릭터) 회전 구현(유니티 2D 기초 강좌) - Transform Rotate를 이용한 캐릭터 회전 방법. Unity C# Script Tutorial

by Ncube 2020. 11. 27.

 

 

유니티의 Transform요소 중 Rotate을 이용한 캐릭터 회전 구현

 

 

[CODE]

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

public class RotateScript : MonoBehaviour
{
    [Header("회전속도 조절")]
    [SerializeField] [Range(1f, 100f)] float rotateSpeed = 50f;
    void Update()
    {
        //회전(왼쪽회전 Z / 오른쪽회전 X)
        if (Input.GetKey(KeyCode.Z))
            transform.Rotate(0, 0, Time.deltaTime * rotateSpeed, Space.Self);

        if (Input.GetKey(KeyCode.X))
            transform.Rotate(0, 0, -Time.deltaTime * rotateSpeed, Space.Self);
        
    }
}

 

 

댓글