Example #1
0
    // Update is called once per frame
    void Update()
    {
        cameraTurn = device.GetAxis(thumbStick).x;
        if (cameraTurn != 0)
        {
            rotateParent.transform.Rotate(Vector3.up, cameraTurn);
        }
        else
        {
            rb.angularVelocity = Vector3.zero;
        }

        if (controller.GetPressDown(triggerButton))
        {
            IPL.SetRightTriggerInteracting(true);
        }
        if (controller.GetPressUp(triggerButton))
        {
            IPL.SetRightTriggerInteracting(false);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (controller.GetPressDown(triggerButton))
     {
         IPL.SetRightTriggerInteracting(true);
     }
     if (controller.GetPressUp(triggerButton))
     {
         IPL.SetRightTriggerInteracting(false);
     }
     if (controller.GetPressDown(gripButton))
     {
         IPL.SetRightGripInteracting(true);
     }
     if (controller.GetPressUp(gripButton))
     {
         IPL.SetRightGripInteracting(false);
     }
     if (controller.velocity.magnitude > 0)
     {
         IPL.SetRightControllerVelocity(controller.velocity);
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (controller.GetPressDown(triggerButton))
        //IPL.Set_Left_Interacting(true); IPL.Set_Player_Interacting(true);
        {
            IPL.SetRightTriggerInteracting(true);
            if (anthology)
            {
                if (anthology.active)
                {
                    anthology.activate(true);
                }
            }
        }
        if (controller.GetPressUp(triggerButton))
        //IPL.Set_Left_Interacting(false); IPL.Set_Player_Interacting(false);
        {
            IPL.SetRightTriggerInteracting(false);
            if (objectHovering)
            {
                objectHovering.GetComponent <Rigidbody>().isKinematic     = false;
                objectHovering.GetComponent <Rigidbody>().velocity        = controller.velocity + new Vector3(controller.velocity.x * -2, 0, controller.velocity.z * -2);
                objectHovering.GetComponent <Rigidbody>().angularVelocity = controller.angularVelocity;
            }
            Invoke("ClearDelayedHold", .25f);

            if (anthology)
            {
                if (anthology.active)
                {
                    anthology.activate(true);
                }
            }
        }
        if (controller.GetPressDown(gripButton))
        //IPL.Set_Left_Interacting(true); IPL.Set_Player_Interacting(true);
        {
            IPL.SetRightGripped(true);
            if (aimer)
            {
                aimer.SetActive(true);
                if (IPL.rightHand.CurrentlyInteracting)
                {
                    delayedHold = IPL.rightHand.CurrentlyInteracting.GetComponent <NVRInteractableItem>();
                }
                else if (objectHovering && IPL.rightTriggerInteractive)
                {
                    delayedHold = objectHovering;
                }
            }
        }
        if (controller.GetPressUp(gripButton))
        //IPL.Set_Left_Interacting(false); IPL.Set_Player_Interacting(false);
        {
            if (aimer)
            {
                aimer.SetActive(false);
            }

            IPL.SetRightGripped(false);

            /*
             * if (IPL.rightHand.CurrentlyInteracting)
             * {
             *
             *  NVRInteractable test = IPL.rightHand.CurrentlyInteracting;
             *  StartCoroutine(delayForReactivate(test));
             *  test.GetComponent<NVRInteractableItem>().enabled = false;
             *  IPL.rightHand.EndInteraction(test);
             *  test.GetComponent<Rigidbody>().AddForce(raycastOrigin.transform.forward * 500);
             *  StartCoroutine("vibrateRight", .1f);
             *  PlaySound(source, sounds[1], true);
             * }
             * else if (objectHovering && IPL.rightTriggerInteractive)
             * {
             *  NVRInteractableItem test = objectHovering;
             *  objectHovering = null;
             *  test.GetComponent<Rigidbody>().isKinematic = false;
             *  test.GetComponent<Rigidbody>().AddForce(raycastOrigin.transform.forward * 500);
             *  StartCoroutine("vibrateRight", .1f);
             *  PlaySound(source, sounds[1], true);
             * }
             */
            if (delayedHold)
            {
                if (IPL.rightHand.CurrentlyInteracting)
                {
                    IPL.rightHand.EndInteraction(delayedHold);
                }
                else if (objectHovering && IPL.rightTriggerInteractive)
                {
                    objectHovering = null;
                }
                delayedHold.GetComponent <NVRInteractableItem>().enabled = false;
                delayedHold.GetComponent <Rigidbody>().isKinematic       = false;
                delayedHold.GetComponent <Rigidbody>().AddForce(raycastOrigin.transform.forward * 500);
                StartCoroutine("vibrateRight", .1f);
                PlaySound(source, sounds[1], true);
            }
        }

        if (controller.GetPressDown(aButton) || controller.GetPressDown(bButton) || controller.GetPressDown(joystickPress))
        {
            IPL.SetRightButtonInteracting(true);
            anthology.activate(true);
        }
        if (controller.GetPressUp(aButton) || controller.GetPressUp(bButton) || controller.GetPressUp(joystickPress))
        {
            IPL.SetRightButtonInteracting(false);
            anthology.activate(false);
        }


        if (!IPL.GetRightTriggerInteracting())
        {
            hovering       = Physics.OverlapBox(raycastOrigin.transform.position + raycastOrigin.transform.forward * IPL.range, IPL.halfExtents, raycastOrigin.transform.rotation);
            objectHovering = IPL.CheckForObject(hovering, raycastOrigin.transform, true);

            //indicator.transform.position = hovering.transform.position;
            if (objectHovering)
            {
                ringDisplay.transform.position = objectHovering.transform.position;
                ringDisplay.transform.LookAt(Camera.main.transform);
            }
            playedWhoosh = false;
        }
        else
        {
            if (objectHovering) //&& !IPL.rightHand.CurrentlyInteracting)
            {
                if (!playedWhoosh)
                {
                    StartCoroutine("vibrateRight", .1f);
                    PlaySound(source, sounds[0], true);
                    playedWhoosh = true;
                }
                objectHovering.GetComponent <Rigidbody>().isKinematic = true;
                objectHovering.transform.position = Vector3.MoveTowards(objectHovering.transform.position, raycastOrigin.transform.position, IPL.pullSpeed * Time.deltaTime);
            }
        }
        if (objectHovering && IPL.GetRightTriggerInteracting())
        {
            if (objectHovering.GetComponent <PotionStack>())
            {
                pullPotion = true;
            }
            else
            {
                pullPotion = false;
            }
            pullSomething = true;
        }
        else
        {
            pullSomething = false;
        }
        if (objectHovering && !IPL.GetRightTriggerInteracting())
        {
            ringDisplay.enabled = true;
        }
        else
        {
            ringDisplay.enabled = false;
        }
    }