Add gameobject dynamically to scene in Unity3d

后端 未结 2 1064
春和景丽
春和景丽 2020-12-30 01:20

I am creating a scene in which I want to show list of offers. In order to show the offer, I created a prefab with placeholders for the offer details which I will get at runt

2条回答
  •  星月不相逢
    2020-12-30 02:16

    //Drag object prefab to variable in inspector
    public GameObject spawnObject;
    //----------------------------------------
    

    Below will create GameObject using the objects Own Transform settings.

     GameObject clone;
        clone = Instantiate(spawnObject.transform, 
                            spawnObject.transform.position, 
                            spawnObject.transform.rotation) as GameObject;
    

    Below will create GameObject using the objects Parents Transform settings.

     GameObject clone;
        clone = Instantiate(spawnObject.transform, 
                            transform.position, 
                            transform.rotation) as GameObject;
    

    Not sure if this helps, but good luck on your game :)

提交回复
热议问题