x


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.

more ▼

asked Jun 15 '12 at 01:08 AM

jeremy gravatar image

jeremy
31 14 22 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jun 15 '12 at 10:02 AM

Develogamer gravatar image

Develogamer
31 2 5 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5275
x3420
x2584
x2176
x1060

asked: Jun 15 '12 at 01:08 AM

Seen: 505 times

Last Updated: Jun 15 '12 at 10:02 AM