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

public class flashingCOL : MonoBehaviour {

    private bool isColliding;
    private Animator Cube;
    public float Timer_Flash;
    public float Timer_FlashCD;
    bool anim_FlashToIdle = false;

    void Start () {
        Cube = this.GetComponent<Animator>();
        Timer_Flash = 0;
    }

    // Update is called once per frame
    void Update () {
        isColliding = false;
        if (anim_FlashToIdle) {
            Timer_Flash += Time.deltaTime;
        }
        if (Timer_Flash >= Timer_FlashCD) {
            Cube.SetTrigger("idel");
            Timer_Flash = 0;
            anim_FlashToIdle = false;

        }
    }

    void OnTriggerEnter (Collider col) {
        if (isColliding) return;
        isColliding = true;
        /*if (col.gameObject.tag == "sonic") {
            print("1");
            Cube.SetTrigger("Gone");
            print("2");
            Cube.SetTrigger("flash");
            print("3");
        }*/
        /*if (col.tag == "Player") {
            Cube.SetTrigger("Gone");
            Cube.SetTrigger("flash");
        }*/
        if (col.tag == "sonic" && !anim_FlashToIdle) {
            Sonic sonic = col.GetComponent<Sonic>();
            sonic.Reflect();
            if (sonic.type == SonicType.Sense) {
                Cube.SetTrigger("Gone");
                Cube.SetTrigger("flash");
                anim_FlashToIdle = true;
            }
        }
    }

}