using UnityEngine;
using System.Collections;

public class RandomSounds : MonoBehaviour {

    public Transform triangle;
    public float soundTimeMin;
    public float soundTimeMax;
    public AudioClip[] sounds;


    private AudioSource audioSource;

    // Use this for initialization
    void Start () {
        audioSource = GetComponent<AudioSource>();
        StartCoroutine(waitAndSound());
    }

    IEnumerator waitAndSound()
    {
        yield return new WaitForSeconds(Random.Range(soundTimeMin, soundTimeMax));
        if (!triangle.GetComponent<TitleControl>().isStarting())
        {
            audioSource.PlayOneShot(sounds[Random.Range((int)0, sounds.Length)]);
            StartCoroutine(waitAndSound());
        }
    }
}
