bad-piggies-0.1.3-porting/Assets/Scripts/Assembly-CSharp/AudioTimeRandomizer.cs
2024-02-24 22:40:44 -05:00

40 lines
863 B
C#

using System.Collections;
using UnityEngine;
public class AudioTimeRandomizer : MonoBehaviour
{
[SerializeField]
private float minDelay = 1f;
[SerializeField]
private float maxDelay = 2f;
private AudioSource baseAudioSource;
private AudioManager audioManager;
private bool doRandomize = true;
private void Start()
{
baseAudioSource = GetComponent<AudioSource>();
audioManager = AudioManager.Instance;
Assert.IsValid(baseAudioSource, "baseAudioSource");
Assert.Check(!baseAudioSource.loop, "RandomTimeAudio attached to AudioSource that is a loop");
StartCoroutine(SpawnAudios());
}
private void OnDestroy()
{
doRandomize = false;
}
private IEnumerator SpawnAudios()
{
while (doRandomize)
{
yield return new WaitForSeconds(Random.Range(minDelay, maxDelay));
audioManager.PlayOneShotEffect(ref baseAudioSource);
}
}
}