- Home /
How to check if a gameobject is over one another?
Randomly some cubes are falling and i have to catch those cubes using a base which also a cube but of large size. Now if i catch 5 cubes all those 5 cubes should be destroyed, but now the problem is i have to check if all 5 gameobjects are one above the other then only destroy those 5 cubes.
With so little information about your game, it is difficult to give an accurate answer. Typically the this problem would be solved by Physics.RaycastAll() or a Physics.SphereCastAll() in the downward direction. When a block comes to rest, you would use either of these two functions. They will return a list of any colliders they hit in the direction you did the cast. Note they will also find the "base" and any other object below the point of the cast, so you will either have to learn about GameObject.tag and tagging, or you will have to learn about layers and layer masks, to filter out only the blocks you care about.
Your answer
Follow this Question
Related Questions
Why doesn't this script work?? Please help.. 1 Answer
How do I stop a timer with OnTriggerEnter()? 0 Answers
dont instantiate clones 1 Answer