var door : GameObject;
var doorAudio : AudioClip;
var openAnimation : AnimationClip;
var closeAnimation : AnimationClip;
function Awake() {
door.animation.AddClip(openAnimation, "Open");
door.animation.AddClip(closeAnimation, "Close");
}
// Opening Door
function OnTriggerEnter() {
audio.PlayOneShot(doorAudio);
door.animation.Play("Open");
}
// Closing Door
function OnTriggerExit() {
yield WaitForSeconds (3);
audio.PlayOneShot(doorAudio);
door.animation.Play("Close");
}
If you walk through the door, you can hear that the sound is playing multiple times on itself, anyone know a fix for this?
Both sides of the door are separate objects, eh? Well, to solve this problem, create an empty object with the AudioSource and the opening sound attached. Add an empty variable for the AudioSource in your code, attach the AudioSource to the code for both halves, and tell the code to:
if (sourcey.isPlaying == false) {
sourcey.Play();
}
I couldn’t get it to work,this is the error message I got:
Could you maybe write out the code and I can copypasta that, I may have done it wrong I’m guessing. Or maybe I misunderstood something in the empty object.