public void Grab(GameObject go) { if (state != HandState.Releasing && state != HandState.Grabbing) { grabbedObject = go.GetComponent <GrabableObject>(); Debug.Log("GRABBING"); grabbedObject.amputedHand = this; grabbedObject.OnGrab(); grabbedObject.transform.SetParent(transform); state = HandState.Grabbing; } }
void FixedUpdate() { //OVRInput.Update(); MyButtonUpdate(); if (OVRInput.Get(handTrigger) > 0) { grabbing = true; //Debug.Log(OVRInput.Get( OVRInput.Axis1D.PrimaryHandTrigger) +" ; "+OVRInput.Get( OVRInput.Axis1D.SecondaryHandTrigger)); if (grabbedObject == null) { if (myBeam.activeSelf && teleGrab) { GameObject hitTarget; if (CastRayForGrabable(out hitTarget)) { GrabableObject script = hitTarget.GetComponent <GrabableObject>(); if (script != null) { script.OnGrab(myRigid); grabbedObject = hitTarget; } } } else { Collider[] colObjects = Physics.OverlapSphere(transform.position, col.radius, mask); //Debug.Log("Amount: "+colObjects.Length); GrabableObject script; for (int i = 0; i < colObjects.Length; i++) { script = colObjects[i].attachedRigidbody.GetComponent <GrabableObject>(); if (script.grabJoint == null) { script.OnGrab(myRigid); grabbedObject = colObjects[i].attachedRigidbody.gameObject; break; } } } } } else { grabbing = false; if (grabbedObject != null) { grabbedObject.GetComponent <GrabableObject>().Release(); grabbedObject = null; } } /*if(myButton[0].state == ButtonStates.Pressed){ * Debug.Log("Button 0 pressed on "+gameObject.name+" pressed"); * CastRayForMarkable(); * }*/ if (myBeam.activeSelf) { if (CastRayForMenu()) { if (myButton[0].state == ButtonStates.Pressed && hitButton != null) { hitButton.GetComponent <MenuButton>().OnClick(); } } } else { hitButton = null; } if (myBeam.activeSelf && myButton[0].state == ButtonStates.Pressed && hitButton == null) { if (!CastRayForMarkable()) { CreateMark(); } } if (myButton[1].state == ButtonStates.Pressed) { //Debug.Log("Button 1 pressed on " + gameObject.name + " pressed"); myBeam.SetActive(true); } else if (myButton[1].state == ButtonStates.LetGo) { myBeam.SetActive(false); } if (myBeam.activeSelf && myButton[2].state == ButtonStates.Pressed) { Vector3 targetPos; if (CastRayForGround(out targetPos)) { VRMove.singleton.TeleportToPosition(targetPos); } } }