Hi, I have a problem with the Hitboxes of some enemies. Out of necessity I added two Box Collider 2D
s to a enemy (one to make it collider into walls and other objects, except the other enemies and the Player, the other to damage the Player with a OnTriggerEnter
) however when I try to hit them they receive double the damage. Enemies with multiple Hitboxes due to their size and shape also have the same effect too. The code provides the Player with the ability to attack multiple enemies at once with a single attack. So how do I fix it? I’m new to Unity and I’m not sure what to do.
Thanks in advance
void Attacco()
{
Instantiate(taglioDea, attackPoint.position, attackPoint.rotation, attackPoint); //
Collider2D[] hitNemici = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, nemiciLayers);//Nemici = enemy
foreach (Collider2D nemici in hitNemici) // hits all enemies that are in the attack hitbox and subtracts damage
{
Debug.Log("hit");
nemici.GetComponent<Nemici>().DannoEffettivo(dannoTaglio); // enemy take damage
nemici.GetComponent<Contracolpo>().ContraColpoEffettivo(attackPoint); // enemy take knockback
}
}
Some parts of the code are written in Italian… hope you understand anyway