侧边栏壁纸
  • 累计撰写 23 篇文章
  • 累计创建 8 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Unity销毁子物体

付心武士
2024-08-04 / 0 评论 / 0 点赞 / 1 阅读 / 537 字

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);
}
0

评论区