How can I access a Collider's GameObject in script?

I’m getting started on my first real Unity project and I began “training” my AI for the game. I want the AI soldiers (surprise, it’s a shooter game) to see available places to take cover once the Collider of the cover collides with a Sphere Collider (a basic sight range, which is also a Trigger) I parented to the Soldier’s GameObject.

In the Sphere Collider’s script I have the OnTriggerEnter function that gives the Soldier’s script the Collider that came into the Sphere Collider. That Collider is stored into a Collider variable in the Soldier script.

The problem is this: I don’t know how to get GameObjects in the cover’s hierarchy where the cover’s Collider is. I’m trying to access the parent GameObject that is the whole cover with the mesh and it’s collider objects/components, through which I could then access a child GameObject (just to mark a position) I placed next to the cover so the Soldier knows a position where he can hide.

How do you tackle problems like this? Is there an easy way to fix this or do you have a better way to do all of this in some other way? I’m running low on ideas right now…

The hierarchy is a Transform stuff, thus you need it to access any relatives. You have direct reference to the parent and root transforms, and can find by name any other object in the hierarchy with transform.Find(“PathName”):

function OnTriggerEnter(other: Collider){
  // get the parent
  var daddy: GameObject = other.transform.parent.gameObject;
  // get another relative by name:
  var brother: GameObject = other.transform.parent.Find("Body/LeftLeg").gameObject;
  // go straight to the root:
  var bigBoss: GameObject = other.transform.root.gameObject;