Unity脚本实现添加子物体
作者:互联网
主要部分:
public GameObject prefab; //使用预制添加子物体
void Start () {
//f 为需要添加自物体的对象
GameObject fg = GameObject.Find("f");
//第一种 clone
//GameObject _Instance = Instantiate(prefab);
//_Instance.transform.parent =fg.transform;
//第二种 从Resources里进行加载
GameObject pfb = Resources.Load("name") as GameObject;
GameObject _Instance = Instantiate(pfb);
_Instance.transform.parent = f.transform;
}
标签:prefab,GameObject,物体,transform,Instance,Unity,添加,Resources 来源: https://www.cnblogs.com/allyh/p/10987115.html