Distance through path finding.

Currently i am working on a game where i have more then one buildings as targets. Player have to move toward one of them. The environment is like a city where we have a lot of buildings.
Please help me to find the distance between player and the particular building ignoring all other buildings as obstacle.
Please don’t answer like that
var distance = Vector3.Distance(object1.transform.position, object2.transform.position);

I want the distance as to be accessed using pathfinding technique.
Thanks…

If you don’t want a direct distance between two objects (calculated using Vector3.Distance) and want to calculate the distance between the destination and agent using the path that NavMesh agent will follow, then you can use:

NavMeshAgent.remainingDistance