Пример #1
0
        private IEnumerator makeUngrabbable(float waitTime, Transform currentTransform)
        {
            // make ungrabbable
            Grabbable currentGrabbable = currentObjectTransform.gameObject.GetComponent <Grabbable>();

            currentGrabbable.IsGrabbable = false;
            yield return(new WaitForSeconds(waitTime));

            // make grabbable again
            currentGrabbable.IsGrabbable = true;
            ungrabbableCoroutineRunning  = false;
        }
Пример #2
0
        private void grabItem()
        {
            // get current object targeted by raycast
            InteractiveItem currentInteractible = controllerRayCaster.CurrentInteractible;

            // get it's Grabbable component
            currentGrabbable = currentInteractible.gameObject.GetComponent <Grabbable>();
            if (currentGrabbable == null)
            {
                return;
            }

            // don't grab it if it has IsGrabbable = false;
            if (!currentGrabbable.IsGrabbable)
            {
                return;
            }

            // make kinematic
            currentGrabbableRb             = currentGrabbable.gameObject.GetComponent <Rigidbody>();
            currentGrabbableRb.isKinematic = true;

            // calculate distance to obj
            Vector3 controllerPos = OVRInput.GetLocalControllerPosition(KosmosStatics.Controller);

            localToWorld = trackingSpace.localToWorldMatrix;
            Vector3 controllerPosWorld = localToWorld.MultiplyPoint(controllerPos);
            Vector3 objectPos          = currentGrabbable.transform.position;

            DistanceToObj = Vector3.Distance(controllerPosWorld, objectPos);

            isGrabbing = true;

            currentGrabbable.Grabbed();

            // check if it has a ConstrainPosition component
            constrainPosition = currentInteractible.gameObject.GetComponent <ConstrainPosition>();

            // check if it has a SliderControl component
            sliderControl = currentInteractible.gameObject.GetComponent <SliderControl>();
        }