Clone/duplicate an existing GameObject and its children

℡╲_俬逩灬. 提交于 2019-12-02 11:55:03

问题


Is there a C# way in Unity to duplicate an existing GameObject and all of its children? In my case, I have an empty GameObject with a number of Text objects as children and I would like to create a copy of them all, including relative positions, text values, font, colors, etc....

Prefabs won't work easily because I want to copy the object including its current state.


回答1:


The Instantiate function is used to clone any GameObject and its hierarchy.

public GameObject rootObj;

void Start()
{
    GameObject duplicate = Instantiate(rootObj);
}


来源:https://stackoverflow.com/questions/48470802/clone-duplicate-an-existing-gameobject-and-its-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!