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);
}
这篇关于克隆/复制现有的游戏对象及其子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:克隆/复制现有的游戏对象及其子对象
基础教程推荐
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
