GameObject.GetComponentsInChildren

Cambiar al Manual
public Component[] GetComponentsInChildren (Type type, bool includeInactive= false);

Parámetros

typeEl tipo de Component para recuperar.
includeInactiveLos Components inactivos deben ser incluidos en el set encontrado?

Descripción

Devuelve todos los componentes del tipo type en el GameObject, o alguno de sus hijos.

Unity searches for components recursively on child GameObjects. This means that it also includes all the child GameObjects of the target GameObject, and all subsequent child GameObjects.
Note: If the type you request is a derivative of MonoBehaviour and the associated script can not be loaded then this function will return `null` for that component.

using UnityEngine;

public class GetComponentsInChildrenExample : MonoBehaviour { void Start() { Component[] hingeJoints;

hingeJoints = GetComponentsInChildren(typeof(HingeJoint));

if (hingeJoints != null) { foreach (HingeJoint joint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects Component[] hingesInactive = GetComponentsInChildren(typeof(HingeJoint), true);

foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }

public T[] GetComponentsInChildren ();
public T[] GetComponentsInChildren (bool includeInactive);

Parámetros

includeInactiveDeberían los GameObjects inactivos ser incluidos en el conjunto encontrado?

Valor de retorno

T[] Una lista de los componentes encontrados que coincidan con el tipo especificado.

Descripción

Versión genérica. Para más detalles, mira la página de Funciones genéricas.

Note: If the type you request is a derivative of MonoBehaviour and the associated script can not be loaded then this function will return `null` for that component.

using UnityEngine;

public class GetComponentsInChildrenExample : MonoBehaviour { void Start() { HingeJoint[] hingeJoints;

hingeJoints = GetComponentsInChildren<HingeJoint>();

if (hingeJoints != null) { foreach (HingeJoint joint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects HingeJoint[] hingesInactive = GetComponentsInChildren<HingeJoint>(true);

foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }

public void GetComponentsInChildren (List<T> results);
public void GetComponentsInChildren (bool includeInactive, List<T> results);

Parámetros

resultsLista para recibir los componentes encontrados.
includeInactiveDeberían los GameObjects inactivos ser incluidos en el conjunto encontrado?

Descripción

Retorna todos los componentes encontrados a la Lista results.

Note: If the type you request is a derivative of MonoBehaviour and the associated script can not be loaded then this function will return `null` for that component.

using UnityEngine;
using System.Collections.Generic;

public class GetComponentsInChildrenExample : MonoBehaviour { void Start() { List<HingeJoint> hingeJoints = new List<HingeJoint>();

GetComponentsInChildren<HingeJoint>(false, hingeJoints);

if (hingeJoints != null) { foreach (HingeJoint joint in hingeJoints) joint.useSpring = false; } else { // Try again, looking for inactive GameObjects List<HingeJoint> hingesInactive = new List<HingeJoint>();

GetComponentsInChildren<HingeJoint>(true, hingesInactive);

foreach (HingeJoint joint in hingesInactive) joint.useSpring = false; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961