Open Door Once But Sound Plays again when i trigger at the door

Hey Everybody

in my scene i have a door that you can open by pressing F
then it also plays a sound from the doors Audio Source,
but i need the audio to only play one time, since the door cannot be closed again,

So when the door is open and i press F at the open door it stills plays the audio

Can you help me fix script so it doesnt ?

THanks in advance

Here’s my script

// Smothly open a door
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);
}

if(Input.GetKeyDown(“f”) && enter){
open = !open;
audio.Play();
}
}

//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;
}
}

Where you have audio.Play() you need to check whether the door is open already:

if (Input.GetKeyDown("f") && enter) {
    if (!open) audio.Play();
    open = true;
}

That should only play the audio when the door is closed.

The main problem is here

function Update ()
{ 
	if(open)
	{ 
		transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth); 
	}

	if(Input.GetKeyDown("f") && enter && !open)
	{ 
		open = true; 
		audio.Play(); 
	}
 }

By adding open to the if condition now you can only do it once. When you press f and enter and the doors open = false then play the audio and open becomes true. So now that open = true it no longer meets the if statements conditions (input F key(yes), enter(yes), !open(no)) get it?

Thanks for the fast answer

i changed the code to what your wrote but the sound still plays, when door is open and i press f

hmmm, weird…