left and right movement for ai

Hi, just having some trouble getting my Boolean statements to switch so the character will move left once it has hit 4 on the x axis. It works fine if i do it manually.

This is my script so far:

var enemySpeed: int;

var canMoveR : boolean = false;

var canMoveL : boolean = false;

function Update () {

amtToMove = enemySpeed * Time.deltaTime;

if (transform.position.x == -6)

{
canMoveL= false;
canMoveR= true;
}

if(transform.position.x >= -6 && canMoveR == true) {

transform.Translate(Vector3.right * amtToMove);

}

	 if (transform.position.x == 4){
		canMoveR = false;
		canMoveL= true;
			}	

if  (transform.position.x <= 4 && canMoveL == true ) {
		transform.Translate(Vector3.left * amtToMove);

}
if (transform.position.x == -6)

{
canMoveL= false;
canMoveR= true;
}

}

Script still wont switch over after changing the if statements to (transform.position.x <= whatever ). It switches fine on the first if statement at -6. but not for the left movement. Sorry about the bad layout, didn’t copy and paste it correctly.

Ah great thanks everyone! I might try using collisions instead of x position and see how that goes.