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

public class Transmision : MonoBehaviour {

    public System.Action comando;
    public float velocidad;
    public float escala = 0f;
    public SpriteRenderer onda;
    public System.Action accion;
    public bool activa = true;

    private void Awake()
    {
        onda.transform.localScale = Vector3.zero;
    }

    private void Update()
    {
        escala += velocidad * Time.deltaTime;
        if (escala > 5)
            Destroy(gameObject);
        onda.transform.localScale = new Vector3(escala, escala, escala);
        onda.color = new Color(.3f, 9f, 1f, .1f / escala);

        if(activa)
        {
            var distancia = Vector2.SqrMagnitude(ControlNave.instancia.transform.position - transform.position);
            var radio = Mathf.Pow(onda.size.x * .5f * escala, 2);
            if (distancia < radio)
            {
                activa = false;
                accion();
            }
        }
    }
}
