- Home /
animation and sound on collide
Hi, I am trying to open a door with its sound when the player (first person controller) enters a box collider. I have a door object with a large box collider, with "is trigger" checked. I have a simple animation called "door_animation_1", created in Unity with Wrap mode set to Once, and attached to the door object. I have a sound called "door_open" attached to the door object, with all the checks unchecked (no mute, no bypass, no play on awake, no loop).
I have a script attached to the door object, to play the door animation, with the following code:
var myAnimation : AnimationClip;
function OnTriggerEnter(other : Collider){
animation.clip = myAnimation;
animation.Play();
}
and a second script to play the sound, always attached to the door object, with the following code:
var myClip : AudioClip;
function OnTriggerEnter(other : Collider){
audio.clip = myClip;
audio.Play();
}
Of course in the door object properties the play animation script properties have the "My Animation" variable set to "door_animation_1", and the play audio script properties have the "My Clip" variable set to "door_open".
When the player (FPC) enters the box collider, the door opens and disappears, and no audio plays.
Can anyone figure out what my mistakes are and how can I solve this simple task? Thank you!
Answer by Beriss · Dec 22, 2011 at 08:26 AM
Hi, AudioClips are referenced and used by AudioSources to play sounds. To use the sound must define AudioSource.
http://unity3d.com/support/documentation/ScriptReference/AudioClip.html
http://unity3d.com/support/documentation/ScriptReference/AudioSource.html