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

public class BrokenFuse : MonoBehaviour
{
    [SerializeField] private List<AudioClip> smallClips = new List<AudioClip>();
    [SerializeField] private List<AudioClip> largeClips = new List<AudioClip>();
    [SerializeField] private ParticleSystem sparks;
    private AudioSource audioSource;

    private void Awake()
    {
        audioSource = GetComponent<AudioSource>();
    }

    private void Update()
    {
        if (audioSource.isPlaying) return;
        if(sparks.particleCount >= 30)
        {
            audioSource.clip = GetRandomClip(largeClips);
            audioSource.Play();
        }else if(sparks.particleCount >= 5)
        {
            audioSource.clip = GetRandomClip(smallClips);
            audioSource.Play();
        }

    }

    private AudioClip GetRandomClip(List<AudioClip> clips)
    {
        return clips[Random.Range(0, clips.Count)];
    }

}
