Re-Check if within Trigger Volume. Physics2D.Overlap / Return a GameObject
Hey so my player can walk over multiple trigger enters and exits that set a current pickup which works great. The problem is, the player can enter two trigger volumes relatively close to one another, pick one item up, but has to walk out, and back in to the other item's trigger volume for it to register as the next pickup item.
I simply want to call a function to call on trigger exit (when the player picks up a item), if they are currently in the trigger volume of another item and return that GameObject. If there are multiple results it just needs to return the first hit, not a whole list or anything.
I'm assuming this has something to do with Physics2D.OverlapBox but my brain is currently melting down and I can't think it through.
Answer by NineHydras · Aug 16, 2020 at 07:22 PM
Ended up going with a list route, rather than a re-check overlap function. Basically just adding every pickup to a list as you enter and removing them as you leave. Every time you pick up, it checks if the list is > 0, then sets the first in the index as the next pickup item.
Your answer
Follow this Question
Related Questions
How to loop through colliders in OverlapCircle range 0 Answers
OverlapBox not working as expected 0 Answers
OnTriggerEnter doesn't work 0 Answers
4 line code not working! 1 Answer
2D prefabs(Enemy) overlap issue 0 Answers