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