- Home /
OnTriggerEnter, Stay
In game's scene I have some set of cubes. Each cube lays on another so I have a kind of visualised array. And other thing about game is that it is similar to bejeweled game. So I need to find cubes, which stay in one line and have equal color/texture. To find this cubes in every cube I save references to its neighbors and then use it. Everyting looks and works good enough. But! To find neighbours I use trigger colliders with kinematic rigidbodies, I detecting collisions by the OnTriggerStay(), becouse OnTriggerEnter() dont work good in my game. First of all I dont need OnTriggerStay work everytime, but I cannot call it as simple function. OnTriggerStay uses a lot of memory(I use getComponent there, I can not avoid this). So can I somehow call collision detection only when I need it, or I have to write my own function with simple collision detection for cubes? Hope somebody has any ideas.
Answer by whydoidoit · Feb 11, 2014 at 02:10 PM
Use Physics.OverlapSphere when you need it.
Or if the grid is "complete" don't use physics at all and work out where the objects are in a 2d array and use that.
It looks like OverlapSphere is just what I need. Thank you for answer.