// crane hit some object, move it back up
 public void RecoilCrane(bool Drop)
 {
     CraneHandState = CraneHandStates.MOVING_UP;
     if (Drop)
     {
         ObjectHeld = null;
     }
 }
    IEnumerator MoveCraneHandUpDown()
    {
        while (CraneHandState == CraneHandStates.MOVING_UP || CraneHandState == CraneHandStates.MOVING_DOWN)
        {
            switch (CraneHandState)
            {
            case CraneHandStates.MOVING_DOWN:
                if (Piston2.transform.localPosition.y <= -22.5f)
                {
                    CraneHandState = CraneHandStates.STATIONARY_DOWN;
                }
                else
                {
                    Piston2.transform.Translate(0, -1 * Time.deltaTime, 0);
                    if (ObjectHeld != null)
                    {
                        ObjectHeld.transform.Translate(0, -1 * Time.deltaTime, 0);
                    }
                }
                break;

            case CraneHandStates.MOVING_UP:
                if (Piston2.transform.localPosition.y >= -16f)
                {
                    CraneHandState = CraneHandStates.STATIONARY_UP;
                }
                else
                {
                    Piston2.transform.Translate(0, 1 * Time.deltaTime, 0);
                    if (ObjectHeld != null)
                    {
                        ObjectHeld.transform.Translate(0, 1 * Time.deltaTime, 0);
                    }
                }
                break;
            }
            yield return(0);            // executed everyframe
        }
    }
 IEnumerator MoveCraneHandUpDown()
 {
     while(CraneHandState == CraneHandStates.MOVING_UP || CraneHandState == CraneHandStates.MOVING_DOWN) {
         switch(CraneHandState) {
             case CraneHandStates.MOVING_DOWN:
                 if (Piston2.transform.localPosition.y <= -22.5f) {
                     CraneHandState = CraneHandStates.STATIONARY_DOWN;
                 }
                 else {
                     Piston2.transform.Translate(0, -1*Time.deltaTime, 0);
                     if (ObjectHeld != null) {
                         ObjectHeld.transform.Translate(0, -1*Time.deltaTime, 0);
                     }
                 }
             break;
             case CraneHandStates.MOVING_UP:
                 if (Piston2.transform.localPosition.y >=-16f) {
                     CraneHandState = CraneHandStates.STATIONARY_UP;
                 }
                 else {
                     Piston2.transform.Translate(0, 1*Time.deltaTime, 0);
                     if (ObjectHeld != null) {
                         ObjectHeld.transform.Translate(0, 1*Time.deltaTime, 0);
                     }
                 }
             break;
         }
         yield return 0; // executed everyframe
     }
 }
 // crane hit some object, move it back up
 public void RecoilCrane(bool Drop)
 {
     CraneHandState = CraneHandStates.MOVING_UP;
     if (Drop) {
         ObjectHeld = null;
     }
 }
 public void CraneGrab(GameObject other)
 {
     CraneHandState = CraneHandStates.STATIONARY_DOWN;
     ObjectHeld = other;
     RecoilCrane(false);
 }
    // Update is called once per frame
    void Update()
    {
        if (!NearController) return;

        if(Input.GetKeyUp(KeyCode.T)) {
            L2ProblemController l2Controller= GameObject.Find("FlowControllerObject").GetComponent("L2ProblemController") as L2ProblemController;
            l2Controller.flingCage();
        }

        if(Input.GetKeyUp(KeyCode.E)) {
            if (!ShowingControllerUI) {
                ShowingControllerUI = true;
                GController.HideInfoBox();
                GController.DisablePlayer();
                GController.ShowMousePointer();
                GController.ShowInfoBox(L2PC.GetProblemText() + "\n" + usingCont);
                //GController.ShowMousePointer();
            }
            else {
                ShowingControllerUI = false;
                GController.HideInfoBox();
                GController.ShowInfoBox(nearCont);
                GController.EnablePlayer();
                //GController.HideMousePointer();
            }
        }

        if (!ShowingControllerUI)  return;

        if (CraneHandState == CraneHandStates.STATIONARY_UP && Input.GetKey(KeyCode.LeftArrow) && CraneLRHandle.transform.position.z < 14.0f) {
            CraneLRHandle.transform.Translate(0, 0, 2*Time.deltaTime);
            if (ObjectHeld != null) {
                ObjectHeld.transform.Translate(-2*Time.deltaTime, 0, 0);
            }
        }
        else if(CraneHandState == CraneHandStates.STATIONARY_UP && Input.GetKey(KeyCode.RightArrow) && CraneLRHandle.transform.position.z > -2.0f)  {
            CraneLRHandle.transform.Translate(0, 0, -2*Time.deltaTime);
            if (ObjectHeld != null) {
                ObjectHeld.transform.Translate(2*Time.deltaTime, 0, 0);
            }
        }

        if (Input.GetKeyUp(KeyCode.DownArrow)) {
            CraneHandState = CraneHandStates.MOVING_DOWN;
            //MoveCraneHandUpDown();
            StartCoroutine(MoveCraneHandUpDown());
        }
        else if(Input.GetKeyUp(KeyCode.UpArrow)) {
            CraneHandState = CraneHandStates.MOVING_UP;
            //MoveCraneHandUpDown();
            StartCoroutine(MoveCraneHandUpDown());
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!NearController)
        {
            return;
        }


        if (Input.GetKeyUp(KeyCode.T))
        {
            L2ProblemController l2Controller = GameObject.Find("FlowControllerObject").GetComponent("L2ProblemController") as L2ProblemController;
            l2Controller.flingCage();
        }

        if (Input.GetKeyUp(KeyCode.E))
        {
            if (!ShowingControllerUI)
            {
                ShowingControllerUI = true;
                GController.HideInfoBox();
                GController.DisablePlayer();
                GController.ShowMousePointer();
                GController.ShowInfoBox(L2PC.GetProblemText() + "\n" + usingCont);
                //GController.ShowMousePointer();
            }
            else
            {
                ShowingControllerUI = false;
                GController.HideInfoBox();
                GController.ShowInfoBox(nearCont);
                GController.EnablePlayer();
                //GController.HideMousePointer();
            }
        }

        if (!ShowingControllerUI)
        {
            return;
        }

        if (CraneHandState == CraneHandStates.STATIONARY_UP && Input.GetKey(KeyCode.LeftArrow) && CraneLRHandle.transform.position.z < 14.0f)
        {
            CraneLRHandle.transform.Translate(0, 0, 2 * Time.deltaTime);
            if (ObjectHeld != null)
            {
                ObjectHeld.transform.Translate(-2 * Time.deltaTime, 0, 0);
            }
        }
        else if (CraneHandState == CraneHandStates.STATIONARY_UP && Input.GetKey(KeyCode.RightArrow) && CraneLRHandle.transform.position.z > -2.0f)
        {
            CraneLRHandle.transform.Translate(0, 0, -2 * Time.deltaTime);
            if (ObjectHeld != null)
            {
                ObjectHeld.transform.Translate(2 * Time.deltaTime, 0, 0);
            }
        }

        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            CraneHandState = CraneHandStates.MOVING_DOWN;
            //MoveCraneHandUpDown();
            StartCoroutine(MoveCraneHandUpDown());
        }
        else if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            CraneHandState = CraneHandStates.MOVING_UP;
            //MoveCraneHandUpDown();
            StartCoroutine(MoveCraneHandUpDown());
        }
    }
 public void CraneGrab(GameObject other)
 {
     CraneHandState = CraneHandStates.STATIONARY_DOWN;
     ObjectHeld     = other;
     RecoilCrane(false);
 }