You might have to be more specific, but you can defintely do this kind of thing. For instance the standard way of interacting with object is using a line trace:
With a bit of adjustment, this could tell you the distance to the object. There is also ( get distance to ):