Problems with animation script?

I am trying to use animations to make a platform move back and forth repeatedly. I already have the animations, which are named “left” and “right”. I am also using the Character controller for my player. Heres my script:

#pragma strict

var left : boolean = false;

function ()
{
	if (left == false);
	{
		target.animation.play("left");
		left = true;
	}
	
	else
	{
		target.animation.play("right");
		left = false;
	}
}

What I am wondering is why this doesn’t work. I used this tutorial on Youtube to help me and changed it a little bit…
Am I doing something wrong?

Maybe you should to use Animator

And store in it your animations as States, here is a tutorial of how to use Animator Controller

And then, you should have three States “any State”, “left” and “right”. In the Animator Controller make a bool “isLeft” or whatever

And at the end make transitions between the states, for example: “the transition from anyState to left when isLeft = true, the transition from anyState to right when isLeft = false”. (see the video above)

Now in the Script you could do something like this:

#pragma strict

var left : boolean = false;

// UPDATE
Update ()
{
	if (left == true);
	{

		left = true;
	}
	
	else
	{

		left = false;
	}
}

// FIXED UPDATE
FixedUpdate(){

    // SET BOOL "isLeft" OF ANMIATOR TRUE OR FALSE
	target.animator.SetBool("isLeft", left);

}