상세 컨텐츠

본문 제목

[C#] 위치, 크기, 회전

유니티

by simstealer 2022. 7. 21. 10:12

본문

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

public class Move : MonoBehaviour
{
    public Transform childTransform;
    void Start()
    {
        // 위치 변경
        transform.position = new Vector3(0, -1, 0);
        childTransform.position = new Vector3(0, 2, 0);

        // 회전 변경
        transform.rotation = Quaternion.Euler(new Vector3(0, 0, 30));
        childTransform.rotation = Quaternion.Euler(new Vector3(0, 60, 0));
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            transform.Translate(new Vector3(0, 1, 0) * Time.deltaTime);
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            transform.Translate(new Vector3(0, -1, 0) * Time.deltaTime);
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.Rotate(new Vector3(0, 0, 180) * Time.deltaTime);
            childTransform.Rotate(new Vector3(0, 180, 0) * Time.deltaTime);
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.Rotate(new Vector3(0, 0, -180) * Time.deltaTime);
            childTransform.Rotate(new Vector3(0, -180, 0) * Time.deltaTime);
        }
    }
}

'유니티' 카테고리의 다른 글

[Unity] FK/IK  (0) 2022.07.21
[C#] 레이캐스트  (0) 2022.07.21
[C#] 코루틴  (0) 2022.07.21
[C#] Interface  (0) 2022.07.20
[Unity] PlayerPrefs 저장 위치  (0) 2022.07.13

관련글 더보기

댓글 영역