initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlaySoundAtRandomIntervals : MonoBehaviour
|
||||
{
|
||||
public float minSeconds = 5f; // Minimum interval to wait before playing sound.
|
||||
public float maxSeconds = 15f; // Maximum interval to wait before playing sound.
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
StartCoroutine(PlaySound());
|
||||
}
|
||||
|
||||
private IEnumerator PlaySound()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
float waitTime = Random.Range(minSeconds, maxSeconds);
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
audioSource.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user