Transform.position Lerp problem.

Hi! I have a problem when using Vector3.Lerp to do my transorf.position .
The concept is that the object will move to a Target X on the x axis and then do other stuff.
So I have:

public float TargetX;

then i have:

var temp = transform.position.x;
if (TargetX == temp) 
{
 //Done Moving
 ismoving = false;
}
else 
{
 transform.position = Vector3.Lerp (transform.position, new Vector3(TargetX ,transform.position.y,transform.position.z), Time.deltaTime * speed);   					
}

The problem is that the if statment “TargetX == temp” is never true because for some reason the transform stop just before the “TargetX”.

For example, if TargetX = 10.00088 , temp only gets to 10.00087.
How can I fix this and make “ismoving = false;” when it reached the target position i want?

When you want to compare floats like that, you should always think about approximation errors.

You can have a look at this function and use it like :

if (Mathf.Approximately(TargetX,temp))