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

public class ReactObject2D : MonoBehaviour {

    [SerializeField]

    Sprite offState;
    [SerializeField]
    Sprite onState;

    [SerializeField]

    AbilityType t;

    [SerializeField]
    Bridge bridge;

    void Start() {
        print("starting...");


        //var s = GetComponentInParent<ReactionBlock>();
         //t = s.Type;

       // offState = s.OffState;
       // onState = s.OnState;




    }

    bool isTurnedOn;


    Sprite CurrentSprite {
        get {
            if(isTurnedOn) {
                return onState;
            } else {
                return offState;
            }
        }
    }

    void OnTriggerEnter2D(Collider2D col) {
        Debug.Log("trigger enter block2d"+col.transform.name);

        var hitBullet = col.transform.GetComponent<Bullet>();
        if(hitBullet) {
            if(hitBullet.Type.Equals(t)) {
                isTurnedOn = !isTurnedOn;
                transform.GetComponentInChildren<SpriteRenderer>().sprite = CurrentSprite;
                bridge.PlaySlideAnim(isTurnedOn);
            }
        }

    }



}
