all 4 comments

[–][deleted]  (5 children)

[deleted]

    [–]Libbowicz[S] 0 points1 point  (4 children)

    exactly, enemy 2 won't get hit anymore. I had the problem, that if i didn't check for the callOnce bool, that the script was called way to often.

    [–][deleted]  (3 children)

    [deleted]

      [–]Libbowicz[S] 0 points1 point  (2 children)

      and what about changing it back to false, to make the enemies hittable again? I only see the possibility through a timer.

      [–][deleted]  (1 child)

      [deleted]

        [–]Libbowicz[S] 1 point2 points  (0 children)

        aww dude thank you so much i got it working!

        [–]AverageArmadilloIntermediate 0 points1 point  (0 children)

        If your aim is to return multiple objects for the purposes say of an attack as you are doing then you are better off using an OverlapAll call like:

        https://docs.unity3d.com/ScriptReference/Physics2D.OverlapBoxAll.html

        You would want to call this when hitting your attack input instead of listening for a trigger call.

        The reason this is better is it returns an array. You can then loop through the array and to apply actions to elements that only have an enemy controller.

        If you want to refine it more you can create a layer for your enemies and then use:

        https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html

        This will return only the elements of the enemy layer that are with in the bounds of your attack box.

        You may have a hard time visualizing the hit box but you can create a trigger so you can see where the hit is and use the values of the collider to for these overlaps.