using UnityEngine;
using System.Collections;

public class Movable : MonoBehaviour
{

	public static float globalSpeed = 5;
	private Transform mTransform;
	public TrackGenerator trackGenerator;
    public GameObject lastLine = null;
	public Vector3 offset;

	// Use this for initialization
	void Start ()
	{
		mTransform = GetComponent<Transform> ();
        if (lastLine != null)
        {
			mTransform.position = lastLine.GetComponent<Transform>().position + offset;
        }
	}
	
	// Update is called once per frame
	void Update ()
	{
		mTransform.Translate (0, -globalSpeed * Time.deltaTime, 0);

		if (mTransform.position.y < -Camera.main.orthographicSize - 1) {
			trackGenerator.LineDestroyed();

			while(transform.childCount!=0)
			{
				transform.GetChild(0).gameObject.SetActive(false);
				transform.GetChild(0).parent = null;
			}
			Destroy(gameObject);
		}

	}
}
