When you say you want to calculate the "distance for A*", you mean the heuristic, right? The heuristic is an estimate of the distance. And you want to avoid overestimating it. See Admissible heuristic.
Unless we are dealing with teleportation, or some not euclidean geometry, there is no way that units will reach the destination via a shorter path ...
I found a solution.
First of all, download the package in the link and put it in unity.
(required for 2D games)
Then you can follow how to do it from the link below: (Do what is explained up to the GEOMETRY OPTIONS heading.)
Finally, create a script for your object named &...
I found the function what does exactly what I need:
bool ARecastNavMesh::ProjectPointMulti(const FVector& Point, TArray<FNavLocation>& OutLocations, const FVector& Extent,
float MinZ, float MaxZ, FSharedConstNavQueryFilter Filter, const UObject* QueryOwner) const
There is the example of usage: