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

public class ElevatorManager : MonoBehaviour
{

    private bool isActive = false;
    private Vector3 originalPosition;
    public float speed = 1000f;
    private Rigidbody2D rb;
    public float maxDistance = 180f;
    // Start is called before the first frame update
    void Start()
    {
        originalPosition = transform.position;
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        if (!isActive)
        {
            transform.position = originalPosition;
            rb.velocity = Vector2.zero;

        }
        else
        {
            rb.velocity = speed * Vector2.up;
            if ((transform.position - originalPosition).magnitude >= maxDistance)
            {
                rb.velocity = Vector2.zero;
            }
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            isActive = true;
        }
    }


    private void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            isActive = false;
        }
    }
}
