using UnityEngine;

public class CloudBehaviour : MonoBehaviour {

    private const float speed = 0.5f;

    private const float range = 0.4f;

    private bool toLeft;

    private float currentCoord = 0f;

	void Start() {
        toLeft = (Random.Range(0, 2) == 0);
        currentCoord = (toLeft ? -1 : 1) * range;
	}

	void Update() {
        currentCoord += (toLeft ? -1 : 1) * speed * Time.deltaTime;
        transform.Translate(Vector3.up * currentCoord);
        if (toLeft && currentCoord <= -range) {
            currentCoord = -range + 0.01f;
            toLeft = false;
        } else if (!toLeft && currentCoord >= range) {
            currentCoord = range - 0.01f;
            toLeft = true;
        }
	}
}