If it should only hitwork with left, up, right, and down usinguse Raycasts.! Your code will look like this
public float[] CheckCollisions() {
Raycast hit;
float[] collisions = new float[4];
if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
collisions[0] = hit.transform.position - transform.position;
else
collisions[0] = Float.NaN;
//other directions
return collisions;
}
It isn't the most beautiful way - make a Vector3 array with all directions you wanna check and then iterate through, and check current Vector for hit.
Sorry for any mistakes, wrote this with my cellphone.