Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Play(delay: ulong = 0): void;
void Play(ulong delay = 0);
def Play(delay as ulong = 0) as void

Parameters

delayDelay in number of samples, assuming a 44100Hz sample rate (meaning that Play(44100) will delay the playing by exactly 1 sec).

Description

Plays the clip with an optional certain delay.

The delay parameter is deprecated, please use the newer PlayDelayed function instead which specifies the delay in seconds.

Note: To obtain sample accuracy with an AudioClip with a different samplerate (than 44.1 khz) you have to do the math yourselves. Delaying an audiosource with an attached AudioClip with samplerate of, say, 32 khz, with 16k samples(.5 sec) is done by Play(22050). ((44100/32000) * 16000 = 22050).

Note: The AudioSource.PlayScheduled API will give you more accurate control over when the audio clip is played.

	@script RequireComponent(AudioSource)
	function Start() {
		audio.Play();
		// Delay a clip by 1 sec (44100 samples)
		audio.Play(44100);
	}
using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class ExampleClass : MonoBehaviour {
    void Start() {
        audio.Play();
        audio.Play(44100);
    }
}
import UnityEngine
import System.Collections

[RequireComponent(typeof(AudioSource))]
public class ExampleClass(MonoBehaviour):

	def Start() as void:
		audio.Play()
		audio.Play(44100)

See Also: Stop, Pause, clip and PlayScheduled functions.