magnitude normalize help

hi i am making a 2d shooting and i have a enemy script that i don't really understand here is the code

var enemy : Transform;
var speed : float = 10;

function Update () {
    var target : Vector3 = enemy.position;
    var moveDirection : Vector3 = target - transform.position;
    var velocity = rigidbody.velocity;

    if(moveDirection.magnitude < 1){
        velocity =;
        velocity = moveDirection.normalized * speed;
    rigidbody.velocity = velocity;

i copied it from a tutorial and i am pretty new in unity so can someone tell me how to change this script so that the object only tracks on the x axis?

To restrict the motion to a certain plane or axis, you just need to zero-out the values for the other axes in your 'moveDirection' variable. So, immediately after the line which says:

var moveDirection : Vector3 = target - transform.position;

You could have, for example:

// restrict moveDirection to X only
moveDirection.y = 0;
moveDirection.z = 0;


// restrict moveDirection to X-Z plane:
moveDirection.y = 0;