Unity中获取一个物体下所有的子物体的方法
方法1(获取全部子物体,无论子物体SetActive是否为true):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public<
本文介绍了在Unity中获取物体所有子物体的两种方法。方法一是通过递归实现,遍历所有子层级,适用于任何情况。方法二是使用Unity内置的API `GetComponentsInChildren`,可快速获取所有子物体,但默认不包括非活动状态的子物体。了解这两种方法有助于更高效地管理和操作场景中的游戏对象。
方法1(获取全部子物体,无论子物体SetActive是否为true):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public<
6540
1018
4179
5836

被折叠的 条评论
为什么被折叠?