Finding any objects below or above object at ANY POINT?

I am making a 2d endless runner. I have already made my random terrain generation script. I want platforms to find if there is another platform above or below them at ANY point on the object when it is generated. How would this be possible?

Cast two ray from object one up and another down. So in this way you can find any object above or below to that object casting a ray. Here is the scripting reference:

Raycast reference