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

public class WallController : MonoBehaviour
{

    public Vector3 startPosition;
    public Vector3 endPosition;
    public float speed;
    public float waitTime;

    private Vector3 nextPosition;
    private IEnumerator coroutine;
    // Start is called before the first frame update
    void Start()
    {
        nextPosition = endPosition;
    }

    // Update is called once per frame
    void Update()
    {
        MoveWall();
        if (Vector3.Distance(transform.localPosition, nextPosition) <= 0.01f)
        {
            SwitchDestination();
        }
    }

    private void MoveWall() 
    {
        transform.localPosition = Vector3.MoveTowards(transform.localPosition, nextPosition, speed * Time.deltaTime);
    }

    private void SwitchDestination() 
    {
        nextPosition = nextPosition != startPosition ? startPosition : endPosition;
    }
}
