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

public class brokenElevator : MonoBehaviour
{

    // Use this for initialization
    private bool notbroke = false;
    private float useSpeed;
    public float directionSpeed = 0.001f;
    float origY;
    public float distance = 10.0f;

    // Use this for initialization
    void Start()
    {
        origY = -10;    
        useSpeed = directionSpeed;
    }

    // Update is called once per frame
    void OnCollisionExit(Collision collisionInfo)
    {
        if (collisionInfo.transform.tag == "Item") notbroke = true;
        print("No longer in contact with " + collisionInfo.transform.tag);
    }


    void FixedUpdate()
    {
        
        if(notbroke)
        {
            if (origY - transform.position.y > distance)
            {
                useSpeed = directionSpeed; //flip direction
            }
            else if (origY - transform.position.y < -distance)
            {
                useSpeed = -directionSpeed; //flip direction
            }
            transform.Translate(0, useSpeed * Time.deltaTime, 0);
        }
    }
}