find the "father" of the "children"

Hi,

I have one ship model, that has a children. This children is a cube that encapsulates all the ship, and this ship has the tag “ship_bound”.

SHIP

  • bound
  • hull
  • shield

I’m detecting when my ship collides with other ships.
This ship_bound, is a trigger, so i’m detecting when he collides with other triggers.

function OnTriggerEnter(other : Collider)
{
  if(other.collider.tag == "ship_bound")
  {
     Debug.Log("i'm there");
  }
}

So, what i needed is to find the “father” of other, in this case the GameObject (SHIP).
There may be more copys of this ship, so making a FindObject(SHIP) won’t work.
I need to find exactly the father of this ship_bound gameobject.
How can i do this ?

many thanks :slight_smile:

transform.parent will give you the transform of the parent.

other.parent.gameObject will give you the GameObject of the parent.[/code]

Hi Tempest,

Thanks, it works :slight_smile:

Bruno

Hi again,

After all, this is not working.
When i do other.parent.gameObject, i get an error in the console saying ‘parent’ is not a member of ‘UnityEngine.Collider’.

If i do “other.collider.parent.gameObject”, i get
MissingFieldException: Field 'UnityEngine.BoxCollider.parent" not found. Boo.Lang.Runtime.PRopertyDispatcherFactory blablabla"
My colliding object is indeed a child of the object i’m tryng to “contact”.
What am i missing here ?

thanks,
Bruno

Sorry, you have to go to the transform.

other.collider.transform.parent;

I know that’s a lot of parts. Parent linked through the transform, and the transform can be linked to through the collider.

1 Like

That was it :wink:
thanks