- Home /
Finding an object's neighbor C#
Hey everyone! I asked a question not too long ago about how to implement a function that destroys matching blocks in a grid (I'm making a block matching game similar to Pet Rescue Saga). The main issue I'm running into at the moment is figuring out how to find an object's neighbor within the grid. I'm going to attach an image for reference, and if you need any code or anything, let me know! The attached image shows the grid that's currently being drawn by the game. Here's what I'm wanting to do: Let's say the player recognizes that there are 2 or more of the blue blocks touching each other and clicks on those. I want the game to recognize where the player clicks (which it already does) and then finds blocks that are touching or the same color and in the same area of the one that has been clicked and destroy them all. Hopefully what I'm asking for makes sense! Thanks in advance for your help!
The two most common solutions to this problem for question on UA are:
1) $$anonymous$$eep all of your objects in a 2D array. Each object keeps track of its position in the array. On a hit, consult the 2D array.
2) Raycast in the four directions with rays that extend just beyond each object.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to destroy blocks that are matching in color C# 2 Answers
Change Block Position In Block Matching Game C# 2 Answers
Shifting blocks to the right to remove empty spaces - C# 0 Answers