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

public class LeftTriggerScript : MonoBehaviour {

    public float timeToFade;
    public string scene;

    private bool _firstTimeEnter = true;

    private float _timeFading;
    private bool _fading = false;
    private Animator _animator;

	// Use this for initialization
	void Start () {
        _animator = GetComponentInChildren<Animator>();
        _firstTimeEnter = true;
	}
	
	// Update is called once per frame
	void Update () {
	
        if (_fading)
        {
            _timeFading += Time.deltaTime;

            if (_timeFading >= timeToFade)
            {
                SceneManager.LoadScene(scene);
            }
        }

	}

    void OnTriggerEnter2D(Collider2D coll)
    {
        if (coll.gameObject.tag == "Player")
        {
            if (_firstTimeEnter)
            {
                _firstTimeEnter = false;

                if (this.name == "LeftTrigger")
                    GlobalVariables.FINAL_IZQDA++;
                else if (this.name == "RightTrigger")
                    GlobalVariables.FINAL_DCHA++;
            }
            _animator.SetBool("End", true);
            _fading = true;
        }
    }
}
