Moving Cube Help

Hey guys I’m working on a FPS jumping platformer and to make things interesting I want to include obstacles like moving cubes. So the current problem I have is that if the cube’s x position goes beyond 10 then in my mind it should go back. The probelm is that the cube seems to stutter in position. This is probably something simple and I’m just an idiot but I’d appreciate the help.

	public float cubeSpeed = 10.0f;
	public float distance = 10.0f;
	public Vector3 direction = Vector3.left;

//	// Use this for initialization
//	void Start () {
//	
//	}
	
	// Update is called once per frame
	void Update () {
		
		if(transform.position.x >= 10)
		{
				transform.Translate(direction * Time.deltaTime*cubeSpeed);
		}
		
		else{
			transform.Translate(Vector3.right * Time.deltaTime*cubeSpeed);	
		}
	}

Well yeah it freezes in place because from what you have written it goes something like this.

  1. you move it to x>10
  2. now you move it to x<10
  3. again it translates to x>10

You are basically just moving it back and forth.