using UnityEngine;
using System.Collections;

public class Whobble : MonoBehaviour 
{
	public float minOffset;
	public float maxOffset;
	public float speed;

	private float upperBound;
	private float lowerBound;

	void Start () 
	{
		float offset = Random.Range (minOffset, maxOffset);
		upperBound = transform.position.y + offset;
		lowerBound = transform.position.y - offset;

        StartCoroutine(Move());
	}
	
	IEnumerator Move () 
	{
		yield return new WaitForSeconds(Random.Range(1,3));
		while(true)
		{
			transform.Translate(speed * Vector3.up * Time.deltaTime, Space.World);
			if(speed > 0 && transform.position.y >= upperBound)
			{
				speed = -speed;
			}else if(speed < 0 && transform.position.y <= lowerBound)
			{
				speed = -speed;
			}

			yield return null;
		}
	}
}
