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

public class WinningCondition : MonoBehaviour {

    private AudioSource audio;
    private Animation anim;
    private bool onlyOnes = true;
    private AudioSource[] audios;

    [HideInInspector]
    public bool win = false;

    void Start()
    {
        audio = GetComponent<AudioSource>();
        anim = GameObject.FindGameObjectWithTag("AnimationWin").GetComponent<Animation>();
        audios = GameObject.FindGameObjectWithTag("GameManager").GetComponent<MusicManager>().getAudios();
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Collider") && onlyOnes)
        {
            Invoke("Win", 4f);
            
            anim.Play();
            onlyOnes = false;
            win = true;
            audio.Play();
        }
    }

    void Win ()
    {
        Application.LoadLevel("Main Menu");
    }
}
