unit – Incorrect movement with inverse kinematics?

I am writing the IK character to look at the direction of the "enemy" of the object. If the enemy is above him, look at the enemy. The problem here is when the enemy leaves the character range. The character must look forward, and he does. But for a second, you can see a kind of fault movement. Here is my script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookingScript: MonoBehaviour
{

private animator animator;
private PlayerMovement _active; // check if the enemy is within the character range or not
public bool ikActive = false;
Public GameObject rightHandObj;
Public GameObject leftHandObj;
Public transformation lookObj = null;
public floating announcement, sd;

void Home ()
{

_active = GetComponent();
animator = GetComponent();

}

Null update ()
{

lookObj = _active.enemy; // enemy object to watch.

if (_active.actives == false && lookObj) // this provides a smooth movement for IK.
{
ikActive = true;
ad = ad + Time.deltaTime;
sd = sd + Time.deltaTime;
yes (ad> = 1)
{
ad = 1;
}
yes (sd> = 0.15f)
{
sd = 0.15f;
}

}
plus
{
sd = sd - Time.deltaTime;
ad = ad - Time.deltaTime;
ikActive = false;
yes (announcement <= 0)
{
ad = 0.0f;
}
yes (sd <= 0)
{

sd = 0.0f;
}
}

} // End of Uploade

void OnAnimatorIK ()
{
yes (animator)
{

if (ikActive == true)
{

if (lookObj! = null)
{
animator.SetLookAtWeight (ad, sd, 0, 0, 0);
animator.SetLookAtPosition (lookObj.position);

}

if (rightHandObj! = null)
{
animator.SetIKPositionWeight (AvatarIKGoal.RightHand, 1);
animator.SetIKRotationWeight (AvatarIKGoal.RightHand, 1);
animator.SetIKPosition (AvatarIKGoal.RightHand, rightHandObj.transform.position);
animator.SetIKRotation (AvatarIKGoal.RightHand, rightHandObj.transform.rotation);
}

if (leftHandObj! = null)
{
animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, 1);
animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, 1);
animator.SetIKPosition (AvatarIKGoal.LeftHand, leftHandObj.transform.position);
animator.SetIKRotation (AvatarIKGoal.LeftHand, leftHandObj.transform.rotation);
}

}

plus
{

animator.SetLookAtWeight (ad, sd, 0, 0, 0);

if (rightHandObj! = null)
{
animator.SetIKPositionWeight (AvatarIKGoal.RightHand, 1);
animator.SetIKRotationWeight (AvatarIKGoal.RightHand, 1);
animator.SetIKPosition (AvatarIKGoal.RightHand, rightHandObj.transform.position);
animator.SetIKRotation (AvatarIKGoal.RightHand, rightHandObj.transform.rotation);
}

if (leftHandObj! = null)
{
animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, 1);
animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, 1);
animator.SetIKPosition (AvatarIKGoal.LeftHand, leftHandObj.transform.position);
animator.SetIKRotation (AvatarIKGoal.LeftHand, leftHandObj.transform.rotation);
}

} // ends something else

}
} // End IK

}

Can anyone solve the mistake I made here?