Version: 2020.3
언어: 한국어

GameObject.GetComponentInParent

매뉴얼로 전환
public Component GetComponentInParent (Type type);
public Component GetComponentInParent (Type type, bool includeInactive);

파라미터

type Type of component to find.

반환

Component Returns a component if a component matching the type is found. Returns null otherwise.

설명

Retrieves the component of Type type in the GameObject or any of its parents.

This method recurses upwards until it finds a GameObject with a matching component. Only components on active GameObjects are matched.

using UnityEngine;
using System.Collections;

public class GetComponentInParentExample : MonoBehaviour { // Disable the spring on the first HingeJoint component found on any parent object

void Start() { HingeJoint hinge = gameObject.GetComponentInParent(typeof(HingeJoint)) as HingeJoint;

if (hinge != null) hinge.useSpring = false; } }

public T GetComponentInParent (bool includeInactive= false);

반환

T Returns a component if a component matching the type is found. Returns null otherwise.

설명

Generic version of this method.

using UnityEngine;
using System.Collections;

public class GetComponentInParentExample : MonoBehaviour { // Disable the spring on the first HingeJoint component found on any parent object

void Start() { HingeJoint hinge = gameObject.GetComponentInParent<HingeJoint>();

if (hinge != null) hinge.useSpring = false; } }