using UnityEngine;
using System.Collections;

public class RandomMovement : MonoBehaviour {
    private int curDir = Random.Range(0, 2);
    private float xGoal = float.NaN;

    void Update() {
        if (float.IsNaN(xGoal) || (xGoal > transform.localPosition.x && curDir == 0) || (xGoal < transform.localPosition.x && curDir == 1)) {
            curDir = Random.Range(0, 2);
            xGoal = transform.localPosition.x + Random.Range(1f, 3f) * ((curDir == 0) ? -1f : 1f);
        }

        transform.SetLocalX(transform.localPosition.x + 0.01f * ((curDir == 0) ? -1f : 1f));
    }
}
