[Unity][C#]删除父物体所有含有特定组件的子物体
发布日期:2021-05-09 11:42:54 浏览次数:18 分类:精选文章

本文共 1339 字,大约阅读时间需要 4 分钟。

 

...    ///     /// ���������������������������������    ///     /// ���������  
public static void destoryChildGameObject(Transform trans_)
{
if (trans_ != null && trans_.childCount > 0)
{
for (int i = 0; i < trans_.childCount; i++)
{
GameObject.Destroy(trans_.GetChild(i).gameObject);
}
}
}

 

...    ///     /// ���������������������������������������������componentName������������    ///     /// ���������  
/// ������������
public static void destoryChildGameObjectByCompontent(Transform trans_, string componentName)
{
if (trans_ != null && trans_.childCount > 0)
{
for (int i = 0; i < trans_.childCount; i++)
{
Component[] components = trans_.GetChild(i).gameObject.GetComponents();
// Debug.Log(i + " /// " + trans_.GetChild(i).name + "///" + componments2.Length);
for (int j = 0; j < components.Length; j++)
{
// Debug.Log(i + " /// " + trans_.GetChild(i).name + "///" + componments2[j]);
if (components[j].ToString() == trans_.GetChild(i).name + "(" + componentName + ")")
{
GameObject.Destroy(trans_.GetChild(i).gameObject);
}
}
}
}
}

 

 

 

 

���������������

1. ...

2. ...

3. ...

 
上一篇:[Unity][C#]回调函数的实际应用
下一篇:[Unity][Camera][2D][优化]2D摄像机可视范围外不播放动画

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月28日 11时52分45秒