type | 取得するコンポーネントの型 |
includeInactive | 非アクティブのコンポーネントも含めるかどうか |
ゲームオブジェクトまたはその親たちから type
のすべてのコンポーネントを返します
The search for components is carried out recursively on parent objects, so it includes parents of parents, and so on.
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 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; } } }
includeInactive | Determines whether to include inactive components in the found set. |
ジェネリック版。詳細については Generic Functions を参照してください。
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 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; } } }
includeInactive | 非アクティブのコンポーネントも含めるかどうか |
results | 見つかったコンポーネントを受け取るリスト |
ゲームオブジェクトや親のコンポーネントを見つけ、リスト 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 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; } } }