using UnityEngine;
using System.Collections;

public class WaveEffectScript : MonoBehaviour {

	public float initialScale;
	public float finalScale;
	public float deltaScale;

	public float initialAlpha;
	public float finalAlpha;
	public float deltaAlpha;

	public float animDuration;
	public float initAnim;

	public AudioSource audio;

	public bool hasStarted = false;

	// Use this for initialization
	void Start () {
		Init ();
	}

	public void Init(){
		deltaScale = (finalScale - initialScale) / animDuration;
		deltaAlpha = (finalAlpha - initialAlpha) / animDuration;
		this.transform.localScale = new Vector3 (initialScale, initialScale, 1);
		Color color = this.GetComponent<SpriteRenderer> ().color;
		this.GetComponent<SpriteRenderer> ().color = new Color (color.r, color.g, color.b, initialAlpha);
		hasStarted = true;
		audio.Play ();
		initAnim = Time.time;
	}

	// Update is called once per frame
	void Update () {
		if (hasStarted) {
			this.transform.localScale += new Vector3 (deltaScale, deltaScale, 0) * Time.deltaTime;
			Color color = this.GetComponent<SpriteRenderer> ().color;
			this.GetComponent<SpriteRenderer> ().color = new Color (color.r, color.g, color.b, color.a + deltaAlpha * Time.deltaTime);
			if (Time.time - initAnim > animDuration) {
				Destroy (this.gameObject);
			}
		}
	}
}
