/*================================================================
Product:    GGJ-2017
Developer:  Onur Tanrıkulu
Company:    Onur Tanrikulu
Date:       22/01/2017 10:36

Copyright (c) 2017 Onur Tanrikulu. All rights reserved.
================================================================*/

using UnityEngine;

public class WallController : MonoBehaviour
{
   #region Fields
    private Vector2 closedPosition;
    private Vector2 openedPosition;
    private Vector2 targetPosition;
    private const float smooth = 1f;
    private bool isAnimating;
   #endregion
 
   #region Constructors
   // code here
   #endregion
 
   #region Properties
   // code here
   #endregion
 
   #region Methods
    private void Start()
    {
            closedPosition = transform.position;
            openedPosition = new Vector2(transform.position.x, transform.position.y - 4);
    }

    private void Update()
    {
        if (isAnimating)
        {
            transform.position = Vector2.Lerp(transform.position, targetPosition, smooth * Time.deltaTime);

            if (Vector2.Distance(transform.position, targetPosition) < 0.01f)
            {
                isAnimating = false;
                transform.position = targetPosition;
            }
        }
    }

    public void Open()
    {
        targetPosition = openedPosition;
        isAnimating = true;
    }

    public void Close()
    {
        targetPosition = closedPosition;
        isAnimating = true;
    }
   #endregion
}
