- Home /
Question by
AzaiKang · Jun 30, 2020 at 09:02 PM ·
c#collider2dontriggerenter2d
OnTriggerEnter2D triggered twice (or more) on Melee Combat System
I have trouble of fixing my script, I've noticed it was called twice, maybe more up to 5. I used an Edge Collider 2D as a trigger to detect an enemy AI. Once it was called twice, the enemy takes twice the damage.
public class LightAttack : MonoBehaviour
{
public Collider2D lightAttack; // I used an Edge Collider 2D in the Inspector
public int damage = 100;
void OnTriggerEnter2D(Collider2D hitInfo)
{
EnemyHP enemy = hitInfo.GetComponent<EnemyHP>();
if (enemy != null)
{
enemy.TakeDamage(damage); //This command will run the Enemy AI's HP script
}
}
Comment