给名为parent的空对象添加子对象
如图所示
新建一个文件,名为addChildTest.cs
将该脚本文件添加到Parent上
将父对象添加到脚本上
代码如图所示
using UnityEngine;
using System.Collections;
public class AddChildTest : MonoBehaviour {
// Use this for initialization
public GameObject parentObj;
void Start () {
GameObject go = new GameObject("Haha");
go.transform.SetParent(parentObj.transform);
}
// Update is called once per frame
void Update () {
}
}
运行后,结果如下:
本文介绍如何在Unity中为一个名为'Parent'的空对象添加子对象。通过创建并使用一个名为'AddChildTest.cs'的脚本,实现动态创建一个名为'Haha'的游戏对象,并将其作为'Parent'的子对象。
610

被折叠的 条评论
为什么被折叠?



