unity 点到直线的距离

public static float distancePoint2Line(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)
{
float fProj = Vector3.Dot(point - linePoint1, (linePoint1 - linePoint2).normalized);
return Mathf.Sqrt((point - linePoint1).sqrMagnitude - fProj * fProj);
}

推荐阅读更多精彩内容