Version: 2020.1
언어: 한국어

GameObject.GetComponentsInChildren

매뉴얼로 전환
public Component[] GetComponentsInChildren (Type type, bool includeInactive= false);

파라미터

type The type of Component to retrieve.
includeInactive Should Components on inactive GameObjects be included in the found set?

설명

Returns all components of Type type in the GameObject or any of its children.

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

파라미터

includeInactive Should inactive GameObjects be included in the found set?

반환

T[] A list of all found components matching the specified type.

설명

Generic version of this method.

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

파라미터

results List to receive found Components.
includeInactive Should inactive GameObjects be included in the found set?

설명

Return all found Components into List 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; } } }