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

function PlayOneShot (clip : AudioClip, volumeScale : float = 1.0F) : void

Description

Plays an AudioClip.

JavaScripts
// Play impact audio clip when colliding with something
var impact : AudioClip;
function OnCollisionEnter () {
audio.PlayOneShot(impact);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public AudioClip impact;
void OnCollisionEnter() {
audio.PlayOneShot(impact);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

public impact as AudioClip

def OnCollisionEnter():
audio.PlayOneShot(impact)