delay | Delay in number of samples, assuming a 44100Hz sample rate (meaning that Play(44100) will delay the playing by exactly 1 sec). |
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.
If AudioSource.clip is set to the same clip that is playing then
the clip will sound like it is re-started. AudioSource will assume
any Play call will have a new audio clip to play.
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.
using UnityEngine; using System.Collections;
[RequireComponent(typeof(AudioSource))] public class ExampleClass : MonoBehaviour { void Start() { AudioSource audio = GetComponent<AudioSource>(); audio.Play(); audio.Play(44100); } }
See Also: Stop, Pause, clip and PlayScheduled functions.