using UnityEngine;
using System.Collections;

public class MoveAndFade : MonoBehaviour {
    public Vector2 Speed;
    public float maxDistance = 4;
    bool wasVisible = false;
	
	void Update () {
        var pos = transform.position + new Vector3(Speed.x, Speed.y, 0) * Time.deltaTime;
        transform.position = pos;
        maxDistance -= Speed.magnitude*0.001f;

        if (maxDistance <= 0) Destroy(gameObject);
        if (!wasVisible && renderer.isVisible) wasVisible = true;
        if (wasVisible && !renderer.isVisible) Destroy(gameObject);
	}
}
