Movement while Looking At an enemy

function Update(){
var hit : RaycastHit;
    var fwd = transform.TransformDirection(Vector3.forward);

    if (Physics.Raycast (transform.position, fwd, 100)) {
        if (target.gameObject.tag == "Enemy"){
        transform.LookAt(target);
        }
    }
}

I have this script that allows my character to Lock on to an enemy he's facing but he can no longer move left or right and can't rotate as long as he's within range. So I need to ask for 2 things:

1.) A method of free movement while locking onto the target.

2.) A method of breaking the raycast via button press (Disable the lock on feature)

Any help will be appreciated.

1) I don't see why the character can't move left or right, while he is locked on. As for the rotate part, that is because you force him to look at the target, so naturally he cant turn.

2) You could edit your script line to this (you would have to declare toggle in the beginning of the script)

if (Input.GetKeyDown(KeyCode.Space))
    toggle = !toggle;
if (toggle && Physics.Raycast (transform.position, fwd,100)) {

Does this make it work like you want it to?