using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "AudioClipGroup")]
public class AudioClipGroup : ScriptableObject
{
    [Range(0, 2)]
    public float VolumeMin = 1.0f;
    [Range(0, 2)]
    public float VolumeMax = 1.0f;
    [Range(0, 2)]
    public float Pitchmin = 1.0f;
    [Range(0, 2)]
    public float Pitchmax = 1.0f;
    [Range(0, 2)]
    public float Cooldown = 0.1f;

    private float lastPlayTime = 0f;

    public List<AudioClip> AudioClips;

    public void Play()
    {
        if (Time.time - lastPlayTime < Cooldown && Time.time - lastPlayTime > 0) return;
        lastPlayTime = Time.time;

        AudioSource source = AudioSourcePool.instance.GetSource();
        
        source.spatialBlend = 0.0f;
        source.clip = AudioClips[Random.Range(0, AudioClips.Count)];
        source.volume = Random.Range(VolumeMin,VolumeMax);
        source.pitch = Random.Range(Pitchmin,Pitchmax);
        
        source.Play();
    }
}
