Physics2D.Raycast distance

You would need to do two checks, giving slightly-different values on either side of 0.2f, and see which ones hit.

If both hit or if both miss, the object is either too close or too far.

Keep in mind the distance will almost certainly never actually be 0.2f.

Floating (float) point imprecision:

Never test floating point (float) quantities for equality / inequality. Here’s why:

https://starmanta.gitbooks.io/unitytipsredux/content/floating-point.html

“Think of [floating point] as JPEG of numbers.” - orionsyndrome on the Unity3D Forums

1 Like