Measuring distance between object and collider

I might’ve found a solution to my previous question: https://answers.unity.com/questions/1518020/2d-slope-rotation.html

Here’s a pic of what might work: https://answers.unity.com/storage/temp/119560-whatitryingtodo.png

All I need to know is to find out the distance between an object and collider.
Is there any way to measure the distance between an object and a collider? Specifically 2D colliders?

void OnCollisionEnter2D(Collision2D other) {
var DIst = Vector2.Distance(transform.position, other.transform.position);
}

If you want to get the exact position of collision for distance, you can use other.GetContacts() to get an array of all contact points in the collision.