- Home /
Collider is not recognizing multiple objects
i made an ability to freeze the enemies(dusman) that got in to the area of a collider .But when i use the ability some enemies that are on top of each other didnt get the effect . What am i doing wrong?
void OnTriggerStay2D(Collider2D hitInfo)
{
dusman dusman = hitInfo.GetComponent<dusman>();
if (dusman != null && countdown > 5)
{
countdown1 = 0f;
reset = true;
if (reset == true && attack == true)
{
dusman.don();
reset = false;
attack = false;
}
}
}
Answer by NikkF · Mar 13 at 07:18 PM
OnTriggerStay is executed when an object enters the trigger and stays in it, its sort of like the Update() function - unlike Enter or Exit which trigger, of course, when an object enters or exits the trigger.
In this case, i think using OnTriggerEnter2D would work better since it can be triggered once every time a new object enters the trigger, and not repeat every frame.
If this doesn't fix it, then it might be an issue with the enemies themselves, in which case you should do a Debug.Log for every enemy and check if they are being correctly detected in the trigger.
Your answer
Follow this Question
Related Questions
can I scale up screen pixels? 1 Answer
Audio mixed, blending on distance ? 1 Answer
Detecting all surfaces within a field, locations of surfaces included 1 Answer
Plasma Ball Effect 2 Answers
Flashlight Flicker! 2 Answers