distance between two points unity code example
Example 1: unity rotation between 2 points
transform.rotation = Quaternion.FromToRotation(Vector3.up, v3Pos2 - v3Pos1);
Example 2: how to compare distance between 2 objects unity
float distance = Vector3.Distance (object1.transform.position, object2.transform.position);