How do I find a specific component in C#/Unity?

Hi,

So basically, I have a prefab that has children, each child having their own box collider. How can I find a specific box collider from a specific child (e.g. the fourth box collider from the fourth child of the prefab)? I’ve read the API, but the only way they have stated uses depth first search meaning the box collider from the first child will always be found, and none of the ones thereafter.

I would appreciate it if you could help me.

Hi,

If you know that the collider is attached to the forth child, you can use transform.GetChild(3).GetComponent<T> to access it. T must be replaced with the name of the component you are looking for.


See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms