Component.GetComponentsInParent

Unity · Версия 2020.3 LTS · Scripting · Component

Component.GetComponentsInParent

Объявление

public Component[] GetComponentsInParent(Type t, bool includeInactive = false);

Параметры

t Тип компонента для получения.
includeInactive Должны ли неактивные Компоненты быть включены в найденный набор?

Описание

Возвращает все компоненты типа type в GameObject или любом из его родителей.

using UnityEngine;

public class GetComponentsInParentExample : MonoBehaviour
{
    public Component[] hingeJoints;

    void Start()
    {
        // Disable the spring on all HingeJoints
        // in this game object and all its parent game objects
        hingeJoints = (HingeJoint[])gameObject.GetComponentsInParent(typeof(HingeJoint));

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

Объявление

public T[] GetComponentsInParent(bool includeInactive);

Объявление

public T[] GetComponentsInParent();

Параметры

includeInactive Должны ли неактивные Компоненты быть включены в найденный набор?

Описание

Общая версия этого метода.

Обновлено 17 ноября 2026 г.