- Home /
Only Get Parent Collision, not child
I have a parent with a trigger collider and it's child, also with a trigger collider. I have this script on the parent:
void OnTriggerEnter2D (Collider2D c) {
switch (c.tag) {
case "object":
crash ();
break;
}
}
However, when the child touches an "object", crash()
is called. I only want to call it if it's the parent itself colliding.
I still want the child to collide with "object" (and call a different function), but I only want to call crash
if it's the parent colliding, so layers aren't an option as far as I know.
You COULD use layer.. Have the parent and child on different layers. With that just check if gameObject.layer = child layer then do nothing, if gameObject.layer = parent layer then execute crash()..? Just guessing at this.
Answer by Wolfdog · Jun 06, 2015 at 12:09 PM
I resolved this by adding a kinematic rigidbody to the child. The collisions now register seperatelly.
Answer by tebandesade · Jun 04, 2015 at 07:27 PM
Have you tried writing an explicit if statement saying that if(parentcollider collides) call that