GameObject.GetComponentsInParent

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

파라미터

typeThe type of Component to retrieve.
includeInactiveShould inactive Components be included in the found set?

설명

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

The search for components is carried out recursively on parent objects, so it includes parents of parents, and so on.

using UnityEngine;

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

hingeJoints = GetComponentsInParent(typeof(HingeJoint));

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

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

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

파라미터

includeInactiveShould inactive Components be included in the found set?

설명

Generic version. See the Generic Functions page for more details.

using UnityEngine;

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

hingeJoints = GetComponentsInParent<HingeJoint>();

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

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

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

파라미터

includeInactiveShould inactive Components be included in the found set?
resultsList holding the found Components.

설명

Find Components in GameObject or parents, and return them in List results.

using UnityEngine;
using System.Collections.Generic;

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

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

GetComponentsInParent<HingeJoint>(true, hingesInactive);

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