1.通过广播消息销毁
子物体
public void DestroyMySelf()
{
Destroy(gameobject);
}
父物体发送广播
parentObj.BroadcastMassage("DestroyMySelf");
2.遍历删除
public GameObject father;
for (int i = 0; i < father.childCount; i++)
Destroy(Father.GetChild(i).gameObject);
3.给子物体设置相同的tag,然后遍历删除
private GameObject[] Sons;
Sons=GameObject.FindGameObjectsWithTag(“Son”);
foreach(GameObject things in Sons)
{
Destory(things);
}
评论区