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

public class ElevatorScript : MonoBehaviour
{
    public Transform point1;
    public Transform point2;
    private Transform target;
    public float speed = 10.0f;
    public bool canElevate = false;
    public bool canReturn = false;

    private void Start()
    {
        target = point2;
    }

    private void FixedUpdate()
    {
        if (canElevate == true)
        {
            float step = speed * Time.fixedDeltaTime;
            transform.position = Vector3.MoveTowards(transform.position, target.position, step);

            if (canReturn == true)
            {
                if ((point2.position - transform.position).magnitude < 0.1f)
                {
                    target = point1;
                    print("close to target");
                }
                if ((point1.position - transform.position).magnitude < 0.1f)
                {
                    target = point2;
                    print("close to target");
                }
            }
        }
    }

    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Player")
        {
            canElevate = true;
        }
    }
}
