Returning control to Player Camera when Dialogue Panel is no longer active.

Hi, I’m trying to rework some of this script so that control is returned to the Player Camera when the Pixel Crusher’s Dialogue Panel is no longer active.
I tried putting the following into the code, but it isn’t working right.

    if (DialoguePanel.enabled == false) {
            CloseDistanceBoost = 1;
            transform.eulerAngles.y = CCamera.eulerAngles.y;
            CCamera.localEulerAngles.y = 0;
            EnableControls();
            Once = true;

If anyone can please offer a suggestion that would be awesome.

//---------------------------------------- We Set variables
enum options {Walk,Teleport};  // ADD THIS SCRIPT TO THE "Player" OBJECT AND SET THE VARIABLES
var TargetPosition : Transform; //Position that the player will be teleported to or walk smoothly to
var TargetToLook : Transform; //The object the player will have to look for 5 seconds
var Distance : float = 15; //The distance the player will have to come close to the object to start
var OnceWithinRange : options; // walk or teleport options
var WalkSpeed : float = 0.5; //Smooth walk speed
var LookSpeed : float = 3; //Smooth look speed
var LookTime : float = 10; //Time the player will look at the object (Starts when he enters the range)
private var Once : boolean;
private var Seconds : float;
private var CloseDistanceBoost : float = 1;
private var CCamera : Transform;
public var DialoguePanel : GameObject;
//---------------------------------------- Start Function
function Start () {
    CCamera = GameObject.Find("Main Camera").transform;
   

} //Find camera
//---------------------------------------- Update Function
function Update () {
    if (Vector3.Distance(transform.position, TargetToLook.position) <= Distance && Seconds <= LookTime) { // If within Range
        Seconds += 1 * Time.deltaTime; //Count Time

        if (OnceWithinRange == options.Teleport) { //If you have set the player to teleport then
            DisableControls(); //Disable his ability to control the player and
            transform.position = TargetPosition.position; //Teleport to position
            CCamera.LookAt(TargetToLook); //Look instantly at the target
        }
        if (OnceWithinRange == options.Walk) { //If you have set the player to walk then
            DisableControls(); //Disable his ability to control the player and
            if (Vector3.Distance(transform.position, TargetPosition.position) < Distance/5 && CloseDistanceBoost <= 3) {
                CloseDistanceBoost += 1 * Time.deltaTime; } //add close distance boost
            transform.position = Vector3 ((Mathf.Lerp(transform.position.x,TargetPosition.position.x,WalkSpeed*CloseDistanceBoost* Time.deltaTime)),(Mathf.Lerp(transform.position.y,TargetPosition.position.y,WalkSpeed*CloseDistanceBoost* Time.deltaTime)),(Mathf.Lerp(transform.position.z,TargetPosition.position.z,WalkSpeed*CloseDistanceBoost* Time.deltaTime))); //Walk to position
            //above line makes player walk
            CCamera.rotation = Quaternion.Slerp(CCamera.rotation, Quaternion.LookRotation(TargetToLook.position - CCamera.position), LookSpeed * Time.deltaTime);
            //above line will make the player look smoothly the object
        }
    }
    //----------------------------------------------------------- Once the 5 seconds pass , return the controlls to the player (you can replace the code inside the if statement if u want
   // if (Seconds >= LookTime && !Once) {
    //    CloseDistanceBoost = 1;
      //  transform.eulerAngles.y = CCamera.eulerAngles.y;
       // CCamera.localEulerAngles.y = 0;
        //EnableControls();
        //Once = true;
    } //-----------------------------------------------------------

    if (Vector3.Distance(transform.position, TargetPosition.position) > Distance/5 && CloseDistanceBoost != 1) {
        CloseDistanceBoost = 1; } //Reset closedistance boost
}
//---------------------------------------- Disable player movement and camera control
function DisableControls () {
    GetComponent("CharacterMotor").enabled = false;
    GetComponent("MouseLook").enabled = false;
    CCamera.GetComponent("MouseLook").enabled = false;
}
//---------------------------------------- Enable player movement and camera contol
function EnableControls () {
    GetComponent("CharacterMotor").enabled = true;
    GetComponent("MouseLook").enabled = true;
    CCamera.GetComponent("MouseLook").enabled = true;
}

Did you check the following snippet from the original script you posted?

Because the following snippet is inside of function Update(), it’s taking it every frame, and even if you place your part of the code, it’ll not work as it’ll just keep switching the state.