your problem is that you are comparing a Vector3 with a float. You need to return the Vector as a Single number as compared to the Vectorâ€™s X, Y, and Z numbers. Unity provides the magnitude and the sqrMagnitude values for this purpose. (sqr magnitude takes less internal computations, so use it when possible).