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

public class ObstacleDoor : MonoBehaviour
{
    private Vector3 startPosition;
    public Vector3 OpenOffset;
    public bool isOpen;
    public float speed = 0.01f;

    void Start()
    {
        startPosition = transform.position;       
        if(isOpen){
            Open();
        } 
    }

    public void Open(){
        isOpen=true;
        StartCoroutine(MoveTo(startPosition + OpenOffset));
    }

    public void Close(){
        isOpen = false;
        StartCoroutine(MoveTo(startPosition));
    }

    IEnumerator MoveTo(Vector3 newPosition){
        while(Vector3.Distance(transform.position, newPosition) > 0.1f){
            transform.position = Vector3.Lerp(transform.position, newPosition, speed);
            yield return new WaitForFixedUpdate();
        }
    }
}
