Unity使用脚本给已有物体创建子物体

    科技2022-07-21  123

    using UnityEngine; using System.Collections; public class GiveParent : MonoBehaviour { string fullPath = "...";//模型数据的路径 void Start(){ GameObject tem = new GameObject(Path.GetFileNameWithoutExtension(fullPath)); tem.transform.parent = this.transform; } }

    在脚本中添加如上代码,并将脚本挂到父对象上即可。对于已存在的两个对象,也可通过transform变量设置对象的继承关系。

    Processed: 0.022, SQL: 8