3
\$\begingroup\$

Is there a way I can have an audio sample play after a certain amount of time, like 3 seconds in JavaScript? I've looked everywhere and can't seem to find what I'm looking for! I'm very new to this type of stuff, so apologies for the kind of daft question...

Thanks

\$\endgroup\$
2
\$\begingroup\$

Use Invoke function to call play sound , pass the time delay which you want. You can do it like this.

function Start() 
{
   audio = GetComponent.<AudioSource>();
   Invoke("PlaySound", 3);
}

function PlaySound() 
{
    audio.PlayOneShot(impact, 0.7F);
}
\$\endgroup\$
2
  • \$\begingroup\$ How do I choose the "AudioSourse"? thanks:) \$\endgroup\$ Nov 4 '15 at 4:31
  • \$\begingroup\$ The audio source component should be attached to the game object to which this script is attached. And the audio clip can be dragged dropped into the audio source through the editor. \$\endgroup\$
    – Hash Buoy
    Nov 4 '15 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .