Calculate how far a ray has intercepted an object.

Lets say I've cast the following ray (in C#) to act as a feeler in-front of an object to detect wall collisions:

Physics.Raycast (transform.position, transform.forward*10, out hit, 10, mask);

From the 'hit' information, what would be the quickest way to work out how far the ray has intercepted the object?

All the best, Joel.

something like:

vector3 distanceVector = hit.point - transform.position;
foat distanceToHit = distanceVector.magnitude;

that gets you the linear distance to the object that was hit.