- Home /
How to emit a sound on specific collision.
Hi I need to know how to emit a audio one shot on a specific collision. For example I have a elevator and when it reaches the bottom I want it to play and audio clip, so I put a collider under my elevator and a collider at the bottom of the elevator tunnel, so when the collider at the bottom of the elevator collides with the collider at the bottom of the elevator tunnel it will play an audio clip, but I have no idea how to do this. So if you can help me thanks so much, plus please be specific on where the script or scripts go.
Answer by Develogamer · Jun 15, 2012 at 10:02 AM
if you have a collider set up on the elevator and on the location where you want the clip to be played then the coding is simple:
Use OnTriggerEnter() to detect when the colliders have hit each other, then just make a public variable and click and drag your audio clip into it in the inspector. in OnTriggerEnter() just do yourAudioClip.Play();
explained in a lot more detail here: http://answers.unity3d.com/questions/12546/playing-audio-clip.html