Collide sound

I hope it is very simple.I have a an object and when it is thrown down to the floor i want a sound to be played(just for the collision,like"boop").So,i have the sound clip and i’ve made an audio source on the floor,in which i put the clip.How can i connect the collision with the sound ?I can’t think of a script…

You could use the OnCollisionEnter event to trigger the sound, like this:

function OnCollisionEnter(coll: Collision){
  GetComponent<AudioSource>().Play();
}

The audio source and this script should be assigned to the floor object (it works with the terrain too). Remember to uncheck Play On Awake in the audio source, or you will hear the sound every time the game starts. Set also the Doppler Level to 0, or the sound may become unrecognizable when you’re moving fast. Finally: the object which will fall to the ground must have a rigidbody to trigger the event.

NOTE: This answer was updated to Unity 5 by replacing the audio “variable” with the code GetComponent() (which previous versions of Unity called behind the scenes anyway).

This should give you some hints: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

http://unity3d.com/support/documentation/ScriptReference/AudioSource.Play.html

Any drawback on assigning this script to the throwed object instead?