using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundBank : MonoBehaviour
{
    public AudioClip[] popVoices;
    public AudioClip[] metalVoices;
    public AudioClip meteorFalling, meteorHitting, meteorAlarm, powerUp, idle, metalEnding, popEnding;
    AudioSource source;
    // Use this for initialization
    void Start()
    {
        source = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void PlayPopSound()
    {
        int random = UnityEngine.Random.Range(0, 2);
        if (random == 1)
            source.PlayOneShot(popVoices[UnityEngine.Random.Range(0, 3)]);
    }
    public void PlayMetalSound()
    {
        int random = UnityEngine.Random.Range(0, 2);
        if (random == 1)
            source.PlayOneShot(metalVoices[UnityEngine.Random.Range(0, 4)]);
    }
    public void PlayMeteor()
    {
        StartCoroutine(PlayMeteorSound());
    }

    private IEnumerator PlayMeteorSound()
    {
        source.PlayOneShot(meteorAlarm);
        yield return new WaitForSeconds(1);
        source.PlayOneShot(meteorFalling);
        yield return new WaitForSeconds(0.3f);
        source.PlayOneShot(meteorHitting);
    }
    public void PlayPowerUp()
    {
        source.PlayOneShot(powerUp);
    }
    public void PlayIdle()
    {
        source.PlayOneShot(idle);
    }
    public void PlayPopEnding()
    {
        source.PlayOneShot(popEnding);
        StartCoroutine(WaitforStop());
    }
    public void PlayMetalEnding()
    {
        source.PlayOneShot(metalEnding);
        StartCoroutine(WaitforStop());
    }

    private IEnumerator WaitforStop()
    {
        yield return new WaitForSecondsRealtime(2);
        source.Stop();
    }
}
