Locking onto enemies with the third person controller

Hi there. I've got a simple scene setup with a player using the third person controller from the 3D Platformer tutorial and an enemy. I've got the code found at the bottom here in a function that a I call in LateUpdate with GetButton so that while I hold the button down, the player "locks on" and continuously faces the enemy while moving around him not unlike various 3D action games like Phantasy Star Online, Devil May Cry, etc.

    function Update () {
    var waypoints: GameObject[] = GameObject.FindGameObjectsWithTag("waypoint"); 
    var closest: GameObject; 
    var closestDist = Mathf.Infinity; 

    for (waypoint in waypoints) { 
        var dist = (transform.position - waypoint.transform.position).sqrMagnitude; 

        if (dist < closestDist) { 
            closestDist = dist; 
            closest = waypoint; 
            } 
    } 
    transform.LookAt(closest.transform); 
}

This works almost perfectly. The problem is, when you let go of the button, the player's facing immediately snaps back to the direction you were moving in. So, for example, if you were locked on and moved away from the enemy then let go of the button, the player's facing immediately snaps away from the enemy. I'm assuming this is because LookAt isn't affecting what the Third Person Controller's using to rotate the character's facing in the direction its moving (moveDirection?), however, I'm unsure as to how to use the enemy's position with the movement direction so that when you let go of the button, the player still faces the enemy at that moment until you move him in a different direction. I'd appreciate any help I could get!

while(Vector3.Distance(enemy.position, transform.position) > 0.1){
   var direction : Vector3 = transform.position - enemy.position;
    transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), 0.2* Time.deltaTime);
    transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
    yield;
    }

You can change the while loop to something like while(Enemy is visible on the camera) or whatever. The code above will give u a basis to what u need.

after 10 years i reply, just use bool like… if (input.getbuttondown (“fire1”) { isLocked = true; } dont know if this question still available or not… sory for my bad English ahaha