스파르타 게임개발종합반(Unity)/사전캠프 공부 기록

[Unity] Quaternion.identity의 의미 - InvokeRepeating, Instantiate, Quaternion.identity;

테크러너 2024. 4. 3.

Instantiate로 프리팹을 반복생성하고자 할 때 세 번째 인자 Quaternion.identity의 의미를 알아봅시다.

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

public class Dog : MonoBehaviour
{
    public GameObject food;

    void Start()
    {
        InvokeRepeating("MakeFood", 0f, 0.5f); // 강아지의 Food 반복 생성해주기
    }

    // 강아지의 Food 생성
    void MakeFood()
    {
        float x = transform.position.x;
        float y = transform.position.y;
        Instantiate(food, new Vector2(x, y), Quaternion.identity); // Quaternion.identity : 별도의 회전값을 주지 않겠다는 의미
    }
}

 

InvokeRepeating (반복 실행할 함수명, 몇 초후에 실행할지, 실행주기)

Instantiate (생성할 오브젝트, 생성 위치, 생성된 오브젝트의 회전값)

Quaternion.identity : 별도의 회전값을 주지 않겠다는 의미(기존 그대로 생성)

 

 

결과

 

반응형

댓글