How to use ForEach loop for every object inside a collider, if it somehow differs from 2D collider, it would be nice to know how exactly.
Thanks in forward.
How to use ForEach loop for every object inside a collider, if it somehow differs from 2D collider, it would be nice to know how exactly.
Thanks in forward.
You can’t access every object inside a collider at a given point in time. Instead, you need to maintain a list of objects as they enter and leave the collider, using OnTriggerEnter and OnTriggerExit (see Keeping Track of Targets in a Trigger | Alastair Aitchison).
Alternatively, if you’re using sphere colliders you could use the Physics.OverlapSphere method.
Thanks for the answer.
– Zukas