当前位置:网站首页>How to get all child objects under an object in Unity
How to get all child objects under an object in Unity
2022-08-08 07:04:00 【LCF_CSharp】
UnityThe method to get all sub-objects under an object
方法1(Get all child objects,regardless of child objectsSetActive是否为true):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public List<GameObject> CH = new List<GameObject>();//A list of stored objects
public Material Dissolve;
// Start is called before the first frame update
void Start()
{
FindChild(this.gameObject);//Find all child objects under the node
DoDissolve();
}
void FindChild(GameObject child)
{
//利用for循环 Get all child objects under the object
for (int c = 0; c < child.transform.childCount; c++)
{
//If there are sub-objects under the sub-object Just pass in the child object for callback lookup until the object has no children
if (child.transform.GetChild(c).childCount > 0)
{
FindChild(child.transform.GetChild(c).gameObject);
}
CH.Add(child.transform.GetChild(c).gameObject);
}
}
}
After getting all child objects,可通过listList batches of objects;
Components such as adding or removing its children,Determine whether its child object has a component and so on.
方法二(推荐):
transform.GetComponentsInChildren<Transform>(); //无法获取SetActive为false的子物体
transform.GetComponentsInChildren<Transform>(true); //Get all child objects,无论SetActive是否为true
该方法为Unity内置的API,All components of the corresponding type under the object will be found;
(注意:This method will find itselfTransform)
边栏推荐
- rhcsa第二天
- 【图形学】13 UnityShader语义(一)
- 虚拟机克隆 快照 迁移 删除
- 【EagleEye】2020-ECCV-EagleEye: Fast Sub-net Evaluation for Efficient Neural Network Pruning-论文详解
- 神经网络预测值几乎一样,神经网络为什么能预测
- RHCSA-配置redhat
- Rose essential oil market research: the current market output value exceeds 2.3 billion yuan, and the market demand gap is about 10%
- 略解损失函数
- 神经网络对数据的要求,神经网络分析相关性
- 线程P01——进程 并发 并行 线程的使用
猜你喜欢
随机推荐
神经网络原理的简单介绍,神经网络原理及应用
bp神经网络预测模型原理,神经网络模型怎么预测
Industry Research: Analysis of the Status and Prospects of the Pension Insurance Market in 2022
Unity3D物体上下左右旋转(不受物体自身坐标轴影响)
Rose essential oil market research: the current market output value exceeds 2.3 billion yuan, and the market demand gap is about 10%
Gym 101492E Teamwork 伪dp解法
Yii2中对MongoDB的配置与问题处理
MongoDB常用命令整理
Prompt for Extraction? PAIE:Prompting Arguement Interaction for Event Argument Extraction
P21 美颜相机的实现——提速,重绘,撤回
PHP操作MongoDB的原生CURD方法
Meta-Learning and in-context Learning
C语言实现顺序表的九个常用接口
Yii2中MongoDB的使用方法-CURD
P20 美颜相机的实现——基础铺垫2
RCNN目标检测原文理解
NVIDIA CUDA 高度并行处理器编程(四):性能优化习题
多神经网络模型联合训练,神经网络模型怎么训练
MongoDB配置文件.conf配置项介绍
P17 五子棋的实现4 悔棋功能









