private void InteractWithObject(out GameObject hit)
 {
     if (ObjectFound(out hit))//ray cast detection
     {
         if (hit.transform.name.Contains("LimbLight"))
         {
             LimbLight limbLightBox = hit.transform.GetComponent <LimbLight>();
             if (limbLightBox.IsLimbAttached())
             {
                 limbLightBox.RemoveLimbFromLightBox(this.transform.parent.tag);
             }
             else
             {
                 limbLightBox.AttachLimbToLightBox(this.transform.parent.tag);
             }
         }
         else if (hit.transform.name.Contains("LightEmitter"))
         {
             hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
             hit.transform.GetComponent <LightEmitter>().switchedOn = !hit.transform.GetComponent <LightEmitter>().switchedOn;
             Debug.Log("light emitter hit");
         }
         else if (hit.transform.name.Contains("RotateBox"))
         {
             if (hit.transform.parent.GetComponent <SCR_Rotatable>().rotatableObjectString.Contains("LightEmitter"))
             {
                 hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
             }
         }
         else if (hit.transform.name.Contains("Switch"))
         {
             hit.transform.GetComponentInChildren <TimelinePlaybackManager>().PlayTimeline();
         }
     }
 }
    // Update is called once per frame
    private void Update()
    {
        var inputDevice = (InputManager.Devices.Count > playerNum) ? InputManager.Devices[playerNum] : null;

        if (inputDevice == null)
        {
            //Debug.Log ("no controllers plugged in");
            if (!holding)
            {
                RaycastHit hit;
                if ((Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[9]) &&
                     isBlue == GameManager.Instance.whichAndroid.player1ControlBlue
                     ) ||
                    Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[22]) &&
                    isBlue != GameManager.Instance.whichAndroid.player1ControlBlue)
                {
                    if (ObjectFound(out hit))                    //ray cast detection
                    {
                        //if the object the player is trying to pick up is the SlideBox (object attached to the pole)
                        if (hit.transform.name.Contains("SlideBox"))
                        {
                            pickedUpGameObject = hit.transform.gameObject;
                            Vector3 temp = pickedUpGameObject.transform.position;
                            if ((int)pickedUpGameObject.transform.parent.right.x == 0)
                            {
                                temp.z = this.transform.position.z;
                            }
                            else
                            {
                                temp.x = this.transform.position.x;
                            }

                            pickedUpGameObject.transform.position = temp;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Movable>().pickedUp  = true;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Movable>().playerTag = this.tag;
                            holding = true;
                        }
                        //if the object the player is trying to pick up is the RotateBox
                        else if (hit.transform.name.Contains("RotateBox"))
                        {
                            pickedUpGameObject = hit.transform.gameObject;

                            AkSoundEngine.PostEvent("Arm_Attach", gameObject);

                            //when you "pick up" the box it will rotate to face the same direction as the player
                            //float speed = 200.0f;
                            //float step = speed * Time.deltaTime;
                            //pickedUpGameObject.transform.rotation = Quaternion.RotateTowards (pickedUpGameObject.transform.rotation,
                            //	this.transform.rotation, step);

                            this.GetComponent <InControlMovement>().enabled = false;

                            pickedUpGameObject.transform.parent.GetComponent <SCR_Rotatable>().pickedUp  = true;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Rotatable>().playerTag = this.tag;
                            holding = true;
                        }
                        else
                        {
                            GenericPickUpCheck(ref hit);
                        }
                    }
                }
                else if ((Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[11]) &&
                          isBlue == GameManager.Instance.whichAndroid.player1ControlBlue
                          ) ||
                         Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[24]) &&
                         isBlue != GameManager.Instance.whichAndroid.player1ControlBlue)
                {
                    if (ObjectFound(out hit))                     //ray cast detection
                    {
                        if (hit.transform.name.Contains("LimbLight"))
                        {
                            LimbLight limbLightBox = hit.transform.GetComponent <LimbLight>();
                            if (limbLightBox.IsLimbAttached())
                            {
                                limbLightBox.RemoveLimbFromLightBox(this.tag);
                            }
                            else
                            {
                                limbLightBox.AttachLimbToLightBox(this.tag);
                            }
                        }
                        else if (hit.transform.name.Contains("LightEmitter"))
                        {
                            hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
                            hit.transform.GetComponent <LightEmitter>().switchedOn = !hit.transform.GetComponent <LightEmitter>().switchedOn;
                        }

                        else if (hit.transform.name.Contains("RotateBox"))
                        {
                            if (hit.transform.parent.GetComponent <SCR_Rotatable>().rotatableObjectString.Contains("LightEmitter"))
                            {
                                hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
                            }
                        }
                    }
                }
            }
            else
            {
                if (pickedUpGameObject.transform.name.Contains("SlideBox"))
                {
                    Vector3 temp = pickedUpGameObject.transform.position;
                    if ((int)pickedUpGameObject.transform.parent.right.x == 0)
                    {
                        temp.z = this.transform.position.z;
                    }
                    else
                    {
                        temp.x = this.transform.position.x;
                    }
                    pickedUpGameObject.transform.position = temp;

                    if ((Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[9]) &&
                         isBlue == GameManager.Instance.whichAndroid.player1ControlBlue
                         ) ||
                        Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[22]) &&
                        isBlue != GameManager.Instance.whichAndroid.player1ControlBlue)
                    {
                        Debug.Log("dropped on click");
                        LimitDrop();
                    }
                }
                else if (pickedUpGameObject.transform.name.Contains("RotateBox"))
                {
                    //float speed = 200.0f;
                    //float step = speed * Time.deltaTime;
                    //pickedUpGameObject.transform.rotation = Quaternion.RotateTowards (pickedUpGameObject.transform.rotation,
                    //	this.transform.rotation, step);

                    Vector3 eulerAng = pickedUpGameObject.GetComponent <Transform>().rotation.eulerAngles;
                    bool    left     = (Input.GetKey(GameManager.Instance.playerSetting.currentButton[1]) && isBlue == GameManager.Instance.whichAndroid.player1ControlBlue) ||
                                       (Input.GetKey(GameManager.Instance.playerSetting.currentButton[14]) && isBlue != GameManager.Instance.whichAndroid.player1ControlBlue);
                    bool right = (Input.GetKey(GameManager.Instance.playerSetting.currentButton[3]) && isBlue == GameManager.Instance.whichAndroid.player1ControlBlue) ||
                                 (Input.GetKey(GameManager.Instance.playerSetting.currentButton[16]) && isBlue != GameManager.Instance.whichAndroid.player1ControlBlue);
                    float leftrot  = left ? -1.0f : 0.0f;
                    float rightrot = right ? 1.0f : 0.0f;

                    pickedUpGameObject.transform.rotation = Quaternion.Euler(eulerAng.x, eulerAng.y + leftrot + rightrot, eulerAng.z);


                    if ((Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[9]) &&
                         isBlue == GameManager.Instance.whichAndroid.player1ControlBlue
                         ) ||
                        Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[22]) &&
                        isBlue != GameManager.Instance.whichAndroid.player1ControlBlue)
                    {
                        RotateDrop();
                        this.GetComponent <InControlMovement>().enabled = true;
                    }
                }
                else
                {
                    //if (alpha <= 1.0f)
                    //	alpha += 0.001f;

                    pickedUpGameObject.GetComponent <Transform>().position = pickupLocation.transform.position;                                                                                    // set the picking up object position
                    pickedUpGameObject.GetComponent <Transform>().rotation = Quaternion.Lerp(pickedUpGameObject.GetComponent <Transform>().rotation, this.GetComponent <Transform>().rotation, 1); //make the rotation of object same as camera
                    pickedUpGameObject.GetComponent <Transform>().rotation = new Quaternion(0, pickedUpGameObject.GetComponent <Transform>().rotation.y, 0, pickedUpGameObject.GetComponent <Transform>().rotation.w);

                    if ((Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[9]) &&
                         isBlue == GameManager.Instance.whichAndroid.player1ControlBlue
                         ) ||
                        Input.GetKeyDown(GameManager.Instance.playerSetting.currentButton[22]) &&
                        isBlue != GameManager.Instance.whichAndroid.player1ControlBlue)
                    {
                        PutDownObject();
                    }
                }
            }
        }
        else
        {               //controllers
            if (!holding)
            {
                RaycastHit hit;
                if (inputDevice.Action2.WasPressed)
                {
                    if (ObjectFound(out hit))                    //ray cast detection
                    {
                        //if the object the player is trying to pick up is the SlideBox (object attached to the pole)
                        if (hit.transform.name.Contains("SlideBox"))
                        {
                            pickedUpGameObject = hit.transform.gameObject;
                            Vector3 temp = pickedUpGameObject.transform.position;
                            if ((int)pickedUpGameObject.transform.parent.right.x == 0)
                            {
                                temp.z = this.transform.position.z;
                            }
                            else
                            {
                                temp.x = this.transform.position.x;
                            }

                            pickedUpGameObject.transform.position = temp;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Movable>().pickedUp  = true;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Movable>().playerTag = this.tag;
                            holding = true;
                        }
                        //if the object the player is trying to pick up is the RotateBox
                        else if (hit.transform.name.Contains("RotateBox"))
                        {
                            Debug.Log("hit the rotate box");
                            pickedUpGameObject = hit.transform.gameObject;

                            //when you "pick up" the box it will rotate to face the same direction as the player
                            //float speed = 200.0f;
                            //float step = speed * Time.deltaTime;
                            //pickedUpGameObject.transform.rotation = Quaternion.RotateTowards (pickedUpGameObject.transform.rotation,
                            //	this.transform.rotation, step);
                            this.GetComponent <InControlMovement>().enabled = false;

                            pickedUpGameObject.transform.parent.GetComponent <SCR_Rotatable>().pickedUp  = true;
                            pickedUpGameObject.transform.parent.GetComponent <SCR_Rotatable>().playerTag = this.tag;
                            holding = true;
                        }
                        else
                        {
                            GenericPickUpCheck(ref hit);
                        }
                    }
                }
                else if (inputDevice.Action4.WasPressed)
                {
                    if (ObjectFound(out hit))                     //ray cast detection
                    {
                        if (hit.transform.name.Contains("LimbLight"))
                        {
                            LimbLight limbLightBox = hit.transform.GetComponent <LimbLight>();
                            if (limbLightBox.IsLimbAttached())
                            {
                                limbLightBox.RemoveLimbFromLightBox(this.tag);
                            }
                            else
                            {
                                limbLightBox.AttachLimbToLightBox(this.tag);
                            }
                        }
                        else if (hit.transform.name.Contains("LightEmitter"))
                        {
                            hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
                            hit.transform.GetComponent <LightEmitter>().switchedOn = !hit.transform.GetComponent <LightEmitter>().switchedOn;
                        }
                        else if (hit.transform.name.Contains("RotateBox"))
                        {
                            if (hit.transform.parent.GetComponent <SCR_Rotatable>().rotatableObjectString.Contains("LightEmitter"))
                            {
                                hit.transform.GetComponent <LightEmitter>().InteractWithEmitter();
                            }
                        }
                    }
                }
            }
            else
            {
                if (pickedUpGameObject.transform.name.Contains("SlideBox"))
                {
                    Vector3 temp = pickedUpGameObject.transform.position;
                    if ((int)pickedUpGameObject.transform.parent.right.x == 0)
                    {
                        temp.z = this.transform.position.z;
                    }
                    else
                    {
                        temp.x = this.transform.position.x;
                    }
                    pickedUpGameObject.transform.position = temp;

                    if (inputDevice.Action2.WasPressed)
                    {
                        Debug.Log("dropped on click");
                        LimitDrop();
                    }
                }
                else if (pickedUpGameObject.transform.name.Contains("RotateBox"))
                {
                    //float speed = 200.0f;
                    //float step = speed * Time.deltaTime;
                    //pickedUpGameObject.transform.rotation = Quaternion.RotateTowards (pickedUpGameObject.transform.rotation,
                    //	this.transform.rotation, step);
                    Vector3 eulerAng = pickedUpGameObject.GetComponent <Transform>().rotation.eulerAngles;

                    pickedUpGameObject.transform.rotation = Quaternion.Euler(eulerAng.x, eulerAng.y + inputDevice.LeftStickX, eulerAng.z);

                    if (inputDevice.Action2.WasPressed)
                    {
                        RotateDrop();
                        this.GetComponent <InControlMovement>().enabled = true;
                    }
                }
                else
                {
                    pickedUpGameObject.GetComponent <Transform>().position = pickupLocation.transform.position;                                                                                    // set the picking up object position
                    pickedUpGameObject.GetComponent <Transform>().rotation = Quaternion.Lerp(pickedUpGameObject.GetComponent <Transform>().rotation, this.GetComponent <Transform>().rotation, 1); //make the rotation of object same as camera
                    pickedUpGameObject.GetComponent <Transform>().rotation = new Quaternion(0, pickedUpGameObject.GetComponent <Transform>().rotation.y, 0, pickedUpGameObject.GetComponent <Transform>().rotation.w);

                    if (inputDevice.Action2.WasPressed)
                    {
                        PutDownObject();
                    }
                }
            }
        }
    }