using UnityEngine;
using System.Collections;

public class SpriteExplode : MonoBehaviour {

	public float endScaleFactor;
	public float ScaleSpeed;
	public float lifetime;
	public bool isActive = false;
	private Vector3 scaleTarget;

	// Use this for initialization
	void Start () {

		scaleTarget = this.transform.localScale * endScaleFactor;
	
	}
	
	// Update is called once per frame
	void Update () {
	
		if( isActive)
		{
			this.transform.localScale = Vector3.Lerp( this.transform.localScale, scaleTarget, ScaleSpeed * Time.deltaTime );
		}
		if( ((this.transform.localScale.x - scaleTarget.x) * (this.transform.localScale.x - scaleTarget.x)) < 0.01f)
		{
			this.transform.localScale = scaleTarget;
			Destroy(this.gameObject);
		}


	}

	public void  Activate()
	{
		isActive = true;
		Destroy(this.gameObject, lifetime );
	}

}
