using UnityEngine;
using System.Collections;

public class BoatPlatformMovementScript : MonoBehaviour
{
    public float moveAmount = 2.0F, closeEnough = 0.5F, speed = 0.1F;

    private bool lerping = false;
    private Vector3 startPos;
    private Vector3 targetPos;

    void Update()
    {

        if (Input.GetKey(KeyCode.W))
        {
            LerpMove(false);
            return;
        }
        if (Input.GetKey(KeyCode.S))
        {
            LerpMove(true);
            return;
        }
    }

    private void LerpMove(bool movingRight)
    {
        if (!lerping)
        {
            startPos = transform.position;
            targetPos = new Vector3(startPos.x, startPos.y, startPos.z + (movingRight ? moveAmount : -moveAmount));
        }

        transform.position = Vector3.Lerp(startPos, targetPos, speed * Time.deltaTime);

        if (transform.position.z > targetPos.z - closeEnough)
        {
            lerping = false;
        }
        return;
    }
}
