using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayRandomAudioClip : MonoBehaviour
{
    public float Delay = 0f;
    public List<AudioClip> Clips;
    private AudioSource _audioSource;

    public void Start()
    {
        _audioSource = GetComponent<AudioSource>();
        if (!_audioSource)
        {
            return;
        }

        StartCoroutine(PlayRoutine());
    }

    public IEnumerator PlayRoutine()
    {
        if (Delay > 0)
        {
            yield return new WaitForSeconds(Delay);
        }

        var clip = Clips[Random.Range(0, Clips.Count)];
        if (clip)
        {
            _audioSource.PlayOneShot(clip);
        }
    }
}
