Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closetype | 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; } }
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; } }