using UnityEngine;
using System.Collections;

public class Plattform : MonoBehaviour
{
		public float speed = 0.1f;
		
		Vector2 newPos;
		
		float width;
		float height;

		void Start ()
		{
				width = Camera.main.ViewportToWorldPoint (Vector3.one).x + renderer.bounds.extents.x;
				height = Camera.main.ViewportToWorldPoint (Vector3.one).y;		
		}

		// Update is called once per frame
		void Update ()
		{
				newPos = transform.position;

				newPos.x = newPos.x - speed * Time.deltaTime * 100;

				if (newPos.x < -width) {
						newPos.x += 2 * width;
						
						newPos.y = Random.Range (-height, 0);
				}

				transform.position = newPos;
		}
}
