transform.localPosition = new Vector3(0, 0, hit.distance); code example
Example: how to get local position unity
transform.localPosition.y
transform.localPosition.z
transform.localPosition.x
transform.localPosition.y
transform.localPosition.z
transform.localPosition.x