- Home /
how to use different OnTriggerEnter2D function for 2 collider of a game object?
hi i add a collider to a game object and use OnTriggerEnter2D function to do some action. now i want to add another collider to a child of game object and use OnTriggerEnter2D function to do some another action. any body can help me about this? for ex. a zombie ( has a collider that cover the body) with a head(had a collider) and body, no i want to use OnTriggerEnter2D function to bullet body hit and headshot.
Answer by RufusHolton · Aug 23, 2020 at 07:16 PM
i think u need 2 different scripts one for the head and another for the body and then whatever script is one the head will detect triggers on the head and whatever script is on the body will detect body triggers
for example:
//this script would go on the body
public class Body : MonoBehaviour
{
void OnTriggerEnter2D()
{
//code for body
}
}
//this script would go on the head
public class Head: MonoBehaviour
{
void OnTriggerEnter2D()
{
//code for head
}
}
thank you. i did like what you said before asking. first i added a collider to game object and worked properly. but now i want to add headshot damage, so decreased the size of collider (with an script) and added another col to head( no script) and run the game. the problem is that script add damage when bullet hit the head collider.