I have a zombie enemy. It is a zombie gameObject with a zombie tag and a capsuleCollider2D attached. It has a child object with another capsuleCollider2D attached that is tagged AITrigger and named Zombie_Trigger.
When OnTriggerEnter2D is called it is called twice because there are two colliders on the object. However i can’t differentiate between the two colliders. Col.tag returns the tag of the zombie parent gamObject regardless of whether the child collider is triggered or the parent collider is triggered. How can i disregard the collision of the child or parent object so that onTriggerEnter is only triggered once per object?
My code:
else if (col.tag == "Enemy" || col.tag == "Ally" ){
if (col.gameObject != Caster && collidesEnemy == true){
col.gameObject.GetComponent<Enemy>().takeDamage(baseDamage);
Destroy(gameObject);
}
}
My code should work however in Unity collisions in child objects seem to return everything about the parent and nothing about the child object.
Specifically, i only want the Enemy to take damage once. But i also want it to only collide once as if i don’t fix this it could cause more problems down the road.
Thanks.