OnTriggerEnter calling infinitely

I wanted a code for a door so when the player enters the trigger, the door will open, then if I enter it again it will close, although what happens is when I enter the trigger it is constantly trying to open and close until I walk out of the trigger.

var smooth = 2.0;
var DoorOpenAngle = 90.0;
private var open : boolean;
private var enter : boolean;
private var defaultRot : Vector3;
private var openRot : Vector3;

function Start(){
defaultRot = transform.eulerAngles;
openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
}

//Main function
function Update (){
if(open){
//Open door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
}else{
//Close door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
}

if(enter == true){
open = !open;
}
}


//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
}
}

//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
enter = false;
}
}

Does anyone know how to stop this from happening, it would be much appreciated.

The cause for this is this code from Update()

 if(enter == true){
 open = !open;
 }

which will run each frame and will switch values of open to true and false each frame as long as enter is true i.e. unless your player exits the trigger making your enter false.

Remove that code above from Update loop.

To get the effect of alternate opening and closing as player enters the trigger just flip the values of open inside OnTriggerEnter.

//Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 if (other.gameObject.tag == "Player") {
    open = !open;
 }
 }

Also remove the OnTriggerExit function since it is not needed now as the door opening and closing is only dependent on player entering the trigger and not exiting it.