figure out how far away a object is unity code example
Example: how to compare distance between 2 objects unity
float distance = Vector3.Distance (object1.transform.position, object2.transform.position);
float distance = Vector3.Distance (object1.transform.position, object2.transform.position);