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

public class Bobbing : MonoBehaviour {
    private float spd = 0.1f;
    private bool flip = false;
	// Use this for initialization
	void Start () {
        Invoke("ChangeDir", 0.1f);
    }
	
	// Update is called once per frame
	void Update () {
        
    }

    void ChangeDir()
    {
        transform.position = new Vector3(transform.position.x, transform.position.y+spd, transform.position.z);
        if (spd < 0.2f && flip == false)
        {
            spd += 0.02f;
        }
        else if (spd >-0.5f)
        {
            spd -= 0.02f;
        }
        if(spd>=0.5f)
        {
            flip = true;
        }
        else if (spd<=-0.2f)
        {
            flip = false;
        }
        
        Invoke("ChangeDir", 0.1f);
    }
}
