You're using a function for 3D world physics (PhysX), you want RaycastHit2D (Box2D) instead: https://docs.unity3d.com/ScriptReference/RaycastHit2D-distance.html
There's also Vector2.Distance(object1.transform.position, object2.transform.position) function just in case. Good luck with your thing there, Spellsmith.