leAthlon
leAthlon

Reputation: 744

How to get the parent of the parent of a component?

I've got following hierarchy:

enter image description here

The marked item has a Collider, which gets hit by a raycast. How can I access from the ColliderComponent of the Cylinder upwards to "fass1"?

   RaycastHit e;
   [...]
   e.collider.???

Upvotes: 2

Views: 67

Answers (1)

Chris McFarland
Chris McFarland

Reputation: 6169

If the Cylinder89 object is your e.collider, accessing fass1's Collider can be done with:

e.collider.transform.parent.parent.GetComponent<Collider>();

Upvotes: 2

Related Questions