Okay, I’m working on a door using a script borrowed from an example by someone else. When inside the box collider and pressing “e”, the sound effect (in theory) plays, then the door opening animation plays. BUT: when I press “e”, the door opens like it should, but no audio plays. Can you guys figure out what I might be doing wrong? I’ve used this exact method before and it worked great, but it’s not working now. (NOTE: I’ve got my audio-source volume up as well. It’s a 2d sound.)
Here’s the entire door code:
var timeOpen : float ;
var doorOpenSound : AudioClip;
var doorCloseSound : AudioClip;
private var doorIsOpen : boolean ;
private var doorTimer : float = 0.0 ;
private var isBlocked : boolean = false ;
function Update () {
if(doorIsOpen && isBlocked == false) {
doorTimer += Time.deltaTime ;
if (doorTimer > timeOpen && isBlocked == false) {
ShutDoor () ;
doorTimer = 0.0 ;
if (doorTimer > timeOpen && isBlocked == true) {
doorTimer = 0.0 ;
}
}
}
}
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "Player" && doorIsOpen == false && Input.GetKeyDown("e")){
isBlocked = true ;
OpenDoor () ;
}
}
function OnTriggerStay (other : Collider){
if (doorIsOpen == false && Input.GetKeyDown("e")){
isBlocked = true ;
OpenDoor () ;
if (doorIsOpen == true) {
isBlocked = true ;
}
}
}
function OnTriggerExit (other : Collider){
if(isBlocked == true) {
isBlocked = false ;
doorTimer = 0.0 ;
}
}
function OpenDoor () {
audio.clip = doorOpenSound;
audio.Play();
doorIsOpen = true ;
animation.PlayQueued ("dooropen") ;
}
function ShutDoor () {
audio.clip = doorCloseSound;
audio.Play();
doorIsOpen = false ;
animation.PlayQueued ("doorclose") ;
animation.PlayQueued ("dooridle") ;
}
@script RequireComponent(AudioSource)
@script RequireComponent(BoxCollider)