using UnityEngine;
using System.Collections;

public class TokenScriptBase : MonoBehaviour
{

    public void Start()
    {
        Messenger<Vector2>.AddListener("cube movement", CubeMoved);
    }

    public virtual void ConsumeToken()
    {
        Dispose();
    }

    public void Dispose()
    {
        Messenger<Vector2>.RemoveListener("cube movement", CubeMoved);
        Destroy(this.gameObject);
    }

    void CubeMoved(Vector2 newPt)
    {
        if (Vector2.Distance(newPt, this.TokenPos) == 0)
        {
            this.ConsumeToken();
        }
    }

    Vector2 TokenPos
    {
        get
        {
            if (this == null) return Vector2.zero;
            return new Vector2()
            {
                x = transform.position.x / 2,
                y = transform.position.z / 2
            };
        }
    }
}
