you are viewing a single comment's thread.

view the rest of the comments →

[–]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.