using UnityEngine;
using System.Collections;
using System.Linq;

public enum Direccion { derecha, izquierda };

public class Checkpoint : MonoBehaviour {

    public static int lastCheckboxIndex = -1;
    public AudioClip audioClip;
    private bool entered_;
    public Direccion direccion;
    public Transform particlesPrefab;

    void OnTriggerEnter2D(Collider2D coll)
    {
        if(!entered && coll.tag == "Player")
        {
            Nivel.current.ContactoConCheckpoint(this);
            entered = true;
        }
    }

    public static Checkpoint last
    {
        get { return lastCheckboxIndex > -1 ? Nivel.current.checkpoints[lastCheckboxIndex] : null; }
    }

    public bool entered
    {
        get { return entered_; }
        set
        {
            entered_ = value;
            var v = value ? .7f : .1f;
            GetComponent<SpriteRenderer>().color = new Color(v, v, v);
            if(value)
            {
                GetComponent<Animator>().SetTrigger("reach");
                var p = Instantiate(particlesPrefab).GetComponent<Transform>();
                p.transform.parent = GetComponentsInChildren<Transform>().Last(); ;
                p.transform.localPosition = new Vector3();
                Debug.Log(p.transform.position);
            }
        }
    }
}
