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

[RequireComponent(typeof(SpriteRenderer))]
public class SonarComponent : MonoBehaviour {

    public float m_duration = 1f;
    public float m_scale = 1f;
    float m_maxRadius;
    float m_elapsedTime;
    float m_currentScale;
    float m_currentAlpha;
    float m_scalePerSecond;
    float m_alphaPerSecond;
    SpriteRenderer m_renderer;

    
	// Use this for initialization
	void Awake () {
        m_maxRadius = Camera.main.orthographicSize * 1.5f;
        m_renderer = GetComponent<SpriteRenderer>();
        m_renderer.enabled = true;
        m_currentScale = 0.01f;
        m_scalePerSecond = (m_maxRadius - m_currentScale) / m_duration;
        m_elapsedTime = 0.0f;
        m_currentAlpha = 1f;
        m_alphaPerSecond = 1f / m_duration / m_scale;
	}
	
	// Update is called once per frame
	void Update () {
        if (m_elapsedTime < m_duration)
        {
            m_currentScale += m_scalePerSecond * Time.deltaTime;
            m_currentAlpha -= m_alphaPerSecond * Time.deltaTime;
            transform.localScale = new Vector3(m_currentScale, m_currentScale, 1f);
            m_renderer.color = new Color(m_renderer.color.r, m_renderer.color.g, m_renderer.color.b, m_currentAlpha);
            m_elapsedTime += Time.deltaTime;
        }
        else
        {
            Destroy(gameObject);
        }
		
	}
}
