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
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;
}
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
public AudioClip theClip;
AudioSource PlayAudioClip(
AudioClip clip,
Vector3 position,
float volume) {
GameObject go =
new GameObject(
"One shot audio");
go.transform.position = position;
AudioSource source = go.AddComponent<AudioSource>();
source.clip = clip;
source.volume = volume;
source.Play();
Destroy(go, clip.length);
return source;
}
void Awake() {
PlayAudioClip(theClip, transform.position, 1);
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
public theClip as
AudioClip def PlayAudioClip(clip as
AudioClip, position as
Vector3, volume as single) as AudioSource:
go as
GameObject =
GameObject('One shot audio')
go.transform.position = position
source as AudioSource = go.AddComponent[of AudioSource]()
source.clip = clip
source.volume = volume
source.Play()
Destroy(go, clip.length)
return source
def
Awake():
PlayAudioClip(theClip, transform.position, 1)