Hey,
So I’ve got a door script that works in every way other than playing audio - The script is as follows: (The object has the AudioSource component and i’ve loaded in the audio file on the script component, yet nothing plays. There is an audio listener also.)
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){
isBlocked = true ;
OpenDoor () ;
}
}
function OnTriggerStay (other : Collider){
if (doorIsOpen == false){
isBlocked = true ;
OpenDoor () ;
if (doorIsOpen == true) {
isBlocked = true ;
}
}
}
function OnTriggerExit (other : Collider){
if(isBlocked == true) {
isBlocked = false ;
doorTimer = 0.0 ;
}
}
function OpenDoor () {
GetComponent.().PlayOneShot (doorOpenSound) ;
doorIsOpen = true ;
GetComponent.().PlayQueued (“dooropen”) ;
}
function ShutDoor () {
GetComponent.().PlayOneShot (doorCloseSound) ;
doorIsOpen = false ;
GetComponent.().PlayQueued (“doorclose”) ;
GetComponent.().PlayQueued (“dooridle”) ;
}
@script RequireComponent (AudioSource)
@script RequireComponent (BoxCollider)