공부/Unity & C#

[Unity] Object.Instantiate

knhoo 2024. 1. 31. 01:49
728x90

 


Object Instantiate (Object original, Vector3 position, Quaternion rotation);

Object Instantiate (오브젝트, 위치, 방향);

오브젝트를 원하는 위치에 생성할 때 사용한다.


파라미터(매개변수)

original 생성하고자 하는 오브젝트
position 새 오브젝트를 생성하려는 위치
rotation 새 오브젝트의 방향

사용 예제

using UnityEngine;

public class InstantiateExample : MonoBehaviour
{
    public GameObject prefab;

    void Start()
    {
        for (int i = 0; i < 10; i++)
            Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
    }


참고 링크 : https://docs.unity3d.com/kr/530/ScriptReference/Object.Instantiate.html

728x90