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

public class CyclicalMovement : MonoBehaviour
{
    [SerializeField] float timeOffset;
    [SerializeField] float timeMultiplier;
    [SerializeField] float yMaxDisplacement;
    float timer;

    [SerializeField] bool isObject;
    [SerializeField] float timeUntilFinalWaves;
    Vector2 originalPosition;
    bool canIncrease = true;

    void Start()
    {
        originalPosition = transform.position;
    }
    void Update()
    {
        YMovement();
        OneTimeIncrease();
    }
    void YMovement()
    {
        timer += Time.deltaTime;
        if (isObject)
        {
            transform.position = new Vector2(transform.position.x, originalPosition.y + Mathf.Sin(timer * timeMultiplier + timeOffset) * yMaxDisplacement);
        }
        else
        {
            if (timer >= timeUntilFinalWaves)
            {
                transform.position = new Vector2(transform.position.x, transform.position.y - (20 * Time.deltaTime));
            }
        }
    }

    void OneTimeIncrease()
    {
        if (canIncrease == true && timer >= timeUntilFinalWaves)
        {
            timeMultiplier = timeMultiplier * 4;
            canIncrease = false;
        }
    }
}
