- Home /
Question by
nikitamatskevitch · Mar 07, 2020 at 12:49 PM ·
c#2dcollision detectioncollider2dcollision2d
Bullet hit the collider of a child object
Hello! Tell me, how can I check if a bullet hits the collider of a child through a script that hangs on a parent? By convention, I have a Player (with a script) -> PlayerAnim (a child) -> Head (a child with a 2D collider). Thank you in advance for your response
Comment
Answer by ShadyProductions · Mar 07, 2020 at 01:41 PM
There are a few ways you can do this.
1). You can search up the hierarchy of the object u collided with to see if it has any parents.
(collider.transform.parent)
2). You can set up layers for the children and configure the collision matrix settings which layer can/cannot collide with other layers.
3). You can tag your objects and use CompareTag to see if you collided with the child tag