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

public class Fade : MonoBehaviour {
    private float opacite=1.0F,speed = 0.07F;
    private int baisse = 0;
	private string next;
	private bool gagne;
	public List<AudioSource> sounds;
	void Start(){
		fadeOut();
	}
    public void Update()
    {
        if (opacite > 0 && baisse == 1)
        {
            this.GetComponent<SpriteRenderer>().color = new Color(0F,0F,0F,opacite);
            opacite -= speed;
            if (opacite <= 0)
            {
                baisse = 0;
            }
        }
        if(opacite < 1 && baisse==-1)
        {
            this.GetComponent<SpriteRenderer>().color = new Color(0F, 0F, 0F, opacite);
			opacite += speed/2;
            if(opacite >= 1)
            {	
				SceneManager.LoadScene (next);
            }
        }
    }
    public void fadeIn()
    {
        baisse = -1;
		if (gagne) {
			sounds[0].Play ();
		} else {
			sounds[1].Play ();
		}
    }
    public void fadeOut()
    {
        baisse = 1;
    }
	public void setNext(string n){
		next = n;
	}
	public void setSpeed(float f){
		speed = f;
	}
	public void setGagne(bool b){
		gagne = b;
	}
}
