Checking for collision with a specific child object.

I am trying to understand collisions.

I have a gameobject that has many child objects.

I want to detect a collision when only 1 specific child object is hit.

I only seem to be able to detect collisions with the partent object.

How can I detect if the collision happened with the child object only, and ignore all other child obejct collisions?

Basically if I have:

  • Parent obejct
  • Child 1
  • Child 2
  • Child 3
  • Child 4

and I want to only do something when a gameobject collides with Child 3.

Is that possible? If so can someone give me an example on how to achive this?

Thanks for any help…

Add a tag to Child3 and then check for it in OnCollision() method:

void OnCollisionEnter(Collider collider)
    if(collider.tag == "child3Tag")
        //.. do something

You can identify the child GameObject uniquely (using a tag), or you can put the collision detection script directly in the child GameObject (if this GameObject’s collision should be detected by any other GameObject, I think this option is better).