Clone/duplicate an existing GameObject and its children(克隆/复制现有的游戏对象及其子对象)
问题描述
Unity 中是否有 C# 方法来复制现有游戏对象及其所有子对象?就我而言,我有一个空的 GameObject,其中有许多 Text 对象作为子对象,我想为它们创建一个副本,包括相对位置、文本值、字体、颜色等......
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 不能轻松工作,因为我想复制包括其当前状态的对象.
Prefabs won't work easily because I want to copy the object including its current state.
推荐答案
Instantiate
函数用于克隆任何 GameObject 及其层次结构.
The Instantiate
function is used to clone any GameObject and its hierarchy.
public GameObject rootObj;
void Start()
{
GameObject duplicate = Instantiate(rootObj);
}
这篇关于克隆/复制现有的游戏对象及其子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:克隆/复制现有的游戏对象及其子对象


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01