// Update is called once per frame void Update() { switch (handState) { //If there is no temporary joint and the player is pressing down on the hand trigger with enough pressure (>= 0.5f in this case), //we set the held object’s velocity to zero, and create a temporary joint attached to it. //We then connect that joint to our AttachPoint (by default, the hand itself) //and set the hand state to HOLDING case HandState.TOUCH: // Debug.LogWarning(mHandState); if (temporaryJoint == null && OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touchController) >= 0.5f) { objectHeld.velocity = Vector3.zero; temporaryJoint = objectHeld.gameObject.AddComponent <FixedJoint>(); temporaryJoint.connectedBody = attachedPoint; handState = HandState.HOLD; //if you grab a vinyl, disable its UI, enable follow cube if (objectHeld.gameObject.tag == "vinyl") { VinylScript vinylScript = objectHeld.gameObject.GetComponent <VinylScript>(); vinylScript.DisableUI(); vinylScript.spawnedFollowCube.SetActive(true); } } break; // If the hand state is already in the HOLDING state, //we check that we do have a temporary joint (i.e. that it is not null) //and that the player is releasing enough of the trigger (in this case, < 0.5f). //If so, we immediately destroy the temporary joint, and set it to null signifying that it is no longer in use. //We then throw the object using a throw method (described further below) and set the hand state to EMPTY. case HandState.HOLD: // Debug.LogWarning(mHandState); //disable line renderer while holding objects lineRenderer.gameObject.SetActive(false); if (temporaryJoint != null && OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touchController) < 0.5f) { Object.DestroyImmediate(temporaryJoint); temporaryJoint = null; //To stop collisions with hands when throwing an object gameObject.GetComponent <SphereCollider>().enabled = false; bool isThrown = throwObject(); VinylScript vinylScript = objectHeld.gameObject.GetComponent <VinylScript>(); //if object isn't thrown and its a vinyl then re-enable its UI if (!isThrown) { if (objectHeld.gameObject.tag == "vinyl") { vinylScript.isThrown = false; vinylScript.EnableUI(); vinylScript.FollowArtist(); //handState = HandState.EMPTY; } } else { //if vinyl is thrown then despawn followcube Destroy(vinylScript.spawnedFollowCube); vinylScript.isThrown = true; // vinylScript.spawnedFollowCube.SetActive(false); } //re enable line renderer when letting go of objects lineRenderer.gameObject.SetActive(true); gameObject.GetComponent <SphereCollider>().enabled = true; handState = HandState.EMPTY; } else if (objectHeld == null) { handState = HandState.EMPTY; //re enable line renderer when letting go of objects lineRenderer.gameObject.SetActive(true); } velocityOld = OVRInput.GetLocalControllerAngularVelocity(touchController); break; } }