You should never compare two floats with equality.
Unity has Mathf.Approximately specifically for that reason:
if (Mathf.Approximately(posx, gameObject.transform.position.x) && Mathf.Approximately(posy, gameObject.transform.position.y))
{
setdirection1();
update();
}
Also, according to Unity's documentation for Vector == Vector (emphasis mine):
Returns true if the vectors are equal.
This will also return true for vectors that are really close to being equal.
Thus, you can do:
if (new Vector(posx, posy) == gameObject.transform.position))
{
setdirection1();
update();
}
In my opinion, the safest way would be to have thresholds (and it sounds like you have something similar):
if (gameObject.transform.position.x < posx ...)
or
if (gameObject.transform.position.x > posx ...)