- Home /
OnTriggerEnter2D is called 2 more times in Melee combat system
I am making a 2D Combat System, I'm using the animator to enable and disable the Edge Collider 2D for every 0.1 seconds in each hit. But when it detects the Enemy AI, the code suddenly runs twice, even more than 5. I detected this problem using my Combo counter system. I have the code so maybe you guys can help me whats the problem, thanks!
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LightAttack : MonoBehaviour { public Collider2D lightAttack; //I'm using Edge Collider 2D for this one public int damage = 100; void OnTriggerEnter2D(Collider2D hitInfo) { EnemyHP enemy = hitInfo.GetComponent<EnemyHP>(); if (enemy != null) { enemy.TakeDamage(damage); //This code will run the EnemyHP Script lightAttack.enabled = false; //Disables the Collider2D, I also disable the Collider 2D via animator in Unity } } }
Answer by CodesCove · Jun 28, 2020 at 11:54 PM
check this thread for possible solutions: https://answers.unity.com/questions/738991/ontriggerenter-being-called-multiple-times-in-succ.html