How to compare float for equality?

How to compare float for equality? I try

hit:RaycastHit;

if (hit.transform.position.x - hit.point.x)== 0.5
 {/*todo*/}

And some times it does not working...

Use Mathf.Approximately() !

It's unlikely that floats will be exactly equal, unless they are explicitly set that way. Use a range, or <= and >=, depending on what you want to do.