using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TrainRunner : MonoBehaviour {

	public float trainSpeed = 100.0f;

	private int direction = 1;
	private const float MAX_X = 115;
	private float timestamp = 0;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

	if (Time.time < timestamp) {
		return;
	}

	Vector2 pos = transform.position;

	pos.x = pos.x + direction * trainSpeed * Time.deltaTime;

	if (pos.x > MAX_X) {
		
		pos.x = 0;
		timestamp = Time.time + 10 + Random.value * 5;
	}

	transform.position = pos;

	}
}
