You should be getting a RaycastHit2D object back from your test. You can access the hit info from that to get the distance and other information about the object you hit. Something like the following:
RaycastHit2D leftHitInfo = Physics2D.Linecast(leftStart.position,
leftEnd.position, layerMask);
if(leftHitInfo.collider != null) {
Debug.Log("Left hit! Distance: " + leftHitInfo.distance.ToString());
}
If you're performing this test regularly, I suggest you use the non-alloc version of this method:
int maxReturnedIntersections = 5;
RaycastHit2D[] hitResults = new RaycastHit2D[maxReturnedIntersections];
int hitCount = Physics2D.LinecastNonAlloc(Vector3leftStart.leftposition, Vector3leftEnd.left*2position, hitResults, 1layerMask);
if(hitCount > 0) {
Debug.Log("Left hit! First distance: " + hitResults[0].distance.ToString());
}
Ideally, you'd create the array of hit results outside of your method so you're not creating a new one over and over.