AudioSource.PlayClipAtPoint Manual     Reference     Scripting  
Scripting > Runtime Classes > AudioSource
AudioSource.PlayClipAtPoint

static function PlayClipAtPoint (clip : AudioClip, position : Vector3, volume : float = 1.0F) : void

Description

Plays the clip at position. Automatically cleans up the audio source after it has finished playing.

The audio source that is playing the sound is returned

// Plays the clip at position
var clip : AudioClip;
AudioSource.PlayClipAtPoint(clip, Vector3 (5, 1, 2));

If you want further control over playback, you can use the following code instead.

var theClip : AudioClip;

PlayAudioClip(theClip, transform.position, 1);

function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float)
{
var go = new GameObject ("One shot audio");
go.transform.position = position;
var source : AudioSource = go.AddComponent (AudioSource);
source.clip = clip;
source.volume = volume;
source.Play ();
Destroy (go, clip.length);
return source;
}