- Home /
Question by
bruno-martelli · Feb 28, 2016 at 11:33 AM ·
audiorandomdelay
Play a short audio file, then random delay, then repeat.
it would be useful to be able to play a sound fx with a random delay- for example a squeaky inn sign blowing in the wind. Any ideas?
Comment
Answer by tanoshimi · Feb 28, 2016 at 11:35 AM
Untested, but this should work to play a sound effect randomly somewhere between every 5-10 seconds:
void Start()
{
StartCoroutine("PlaySound");
}
IEnumerator PlaySound()
{
while(true)
{
yield return new WaitForSeconds(Random.Range(5,10));
GetComponent<AudioSource>().Play();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612065915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I play a random sound each 5 seconds? 1 Answer
Randomly play audio 0 Answers
Audio loop after time 2 Answers
Sound playing at random. (JS) 2 Answers
yield WaitForSeconds to delay the instantiation of a game Object; 1 Answer