1
0
Files
LupiNexMedia f84f5c592b initial commit
2026-04-28 09:32:03 +02:00

27 lines
716 B
C#

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();
}
}
}