Checking Surroundings of a cube

I’m trying to write a script to check the surroundings of a cube to see if there are any other adjacent cubes.

My current approach is to give the cubes rigid bodies and then their position and rotation. Then use the following:

ArrayList list = new ArrayList();

void OnCollisionEnter(Collision other){

void Update(){
          for (int i=0,i<list.count,i++){
             if (list *= new Vector3(0,1,0))*

top = true;
if (list = new Vector3(0,-1,0))
bottom = true;
I’m not a huge fan of this approach and I’m looking for either a way to do make this simpler or another way to do it all together.

Often these kinds of problems can be solved by taking advantage of special properties of the game. But in the abstract, I suggest looking at Physics.OverlapSphere(). If you size the radius slightly larger than the diagonal of the block you will get back a list of the near colliders. If they need to be absolutely adjacent, you can check the distance.

Another pretty standard way is to use Physics.Raycast(). Create a ray from the center of the cube that is just slightly longer than half the cube width and cast it in whatever direction you want to detect.

Note I have concerns about your current approach. To consistently get the collision you will not only have to add a rigidbody but also have to move the block through Physics to get the collision. Plus there is always the chance that you’ll get multiple collisions.