Object to walk forward, turn 180 and walk back

I have this object who walks forward, when it gets to a certain x position it should stop, turn 1980 degrees and walk back, then when it gets to the position it started at it turns 180 degrees and walk forward again.

this is how i am trying to get him to walk and turn

public float Speed = 1f;
public float TurnSpeed = 1f;

void Start () {
    transform.position = new Vector3(-10, 0, -79);
}

void Update () {
    transform.Translate(new Vector3(0, 0, 1) * Speed * Time.deltaTime);
    if (transform.position.x < -1)
    {
        transform.Translate(new Vector3(0, 0, 0));
        transform.Rotate(0, 180 * Time.deltaTime, 0);
    }
}

he will keep moving and not stop not sure why any help?

in line 9 you are translating your object on the z axis only, so I don’t think that it will ever move on the x-Axis… this in turn would make your if statement kind of not do what you want. These are just my assumptions, if I miss something obvious please tell me :slight_smile: