private void GrabObject() { objectInHand = collidingObject; HourglassControl hourglassRef = objectInHand.GetComponent <HourglassControl>(); SpellModuleList scrollRef = objectInHand.GetComponent <SpellModuleList>(); CrystalInfo crystalRef = objectInHand.GetComponent <CrystalInfo>(); if (hourglassRef != null) { if (!hourglassRef.interactable) { return; } } collidingObject = null; var joint = AddFixedJoint(); joint.connectedBody = objectInHand.GetComponent <Rigidbody>(); if (objectInHand.GetComponent <VRSlider>() || crystalRef != null || scrollRef != null || hourglassRef != null) { objectInHand.GetComponent <Rigidbody>().isKinematic = false; } if (crystalRef != null) { AudioSource.PlayClipAtPoint(crystalPickup, transform.position, Info.optionsData.sfxLevel); foreach (Animator anim in slotAnimators) { anim.enabled = true; } } if (scrollRef != null) { AudioSource.PlayClipAtPoint(scrollPickup, transform.position, Info.optionsData.sfxLevel); if (scrollRef.transform.parent == null) { creationArea.isSpellCollected = true; } } for (int i = 0; i < beltObjects.Length; i++) // check all slots to see if any are suitable { if (objectInHand.transform.parent == beltObjects[i].transform) { objectInHand.transform.SetParent(null); beltSlots[i] = false; } } }
public void ReleaseObject() { if (GetComponent <FixedJoint>()) { GetComponent <FixedJoint>().connectedBody = null; Destroy(GetComponent <FixedJoint>()); bool isInBelt = false; foreach (bool a in beltSlots) // check all slots to see if any are suitable { if (a) { isInBelt = true; } } bool shouldDestroy = true; #region Destroy on invalid hand if (!isHandInArea) { if (objectInHand.GetComponent <HourglassControl>() != null || objectInHand.GetComponent <VRSlider>() != null || (objectInHand.GetComponent <SpellModuleList>() != null && isInBelt == true)) { shouldDestroy = false; } if (shouldDestroy) { DestroyImmediate(objectInHand); } } #endregion if (objectInHand != null) { if (objectInHand.GetComponent <SpellModuleList>() != null && isInBelt == false) { if (Physics.Raycast(camTransform.position, transform.position - camTransform.position, out RaycastHit hit, 1000f, castingLayermask)) { if (hit.collider.gameObject == gameObject) { SpellModuleList sml = objectInHand.GetComponent <SpellModuleList>(); // if the object is spell sml.obj = this; sml.hand = hand; sml.handTransform = gameObject.transform; sml.projectileVelocity = controllerPose.GetVelocity(); sml.projectileAngularV = controllerPose.GetAngularVelocity(); Spell spellref = objectInHand.GetComponent <Spell>(); spellref.CallSpell(); foreach (Renderer renderer in objectInHand.transform.GetChild(0).GetComponentsInChildren <Renderer>()) { renderer.enabled = false; } foreach (SpriteRenderer render in spellref.symbolSlots) { render.enabled = false; } for (int i = 0; i < 5; i++) { objectInHand.transform.GetChild(0).GetChild(i).gameObject.GetComponent <Renderer>().enabled = false; } } else { DestroyImmediate(objectInHand); } } else { DestroyImmediate(objectInHand); } } else if (objectInHand.GetComponent <SpellModuleList>() != null) // if the spell is on the belt { for (int i = 0; i < beltObjects.Length; i++) // check all slots to see if any are suitable { if (beltSlots[i] == true) { objectInHand.transform.SetParent(beltObjects[i].transform); //objectInHand.transform.localScale = new Vector3(objectInHand.transform.localScale.x / beltObjects[i].transform.localScale.x, //objectInHand.transform.localScale.y / beltObjects[i].transform.localScale.y, objectInHand.transform.localScale.z / beltObjects[i].transform.localScale.z); objectInHand.GetComponent <Rigidbody>().isKinematic = true; beltSlots[i] = false; } } } else if (objectInHand.GetComponent <CrystalInfo>()) // dont apply force to certain released objects { objectInHand.GetComponent <Rigidbody>().isKinematic = true; for (int i = 0; i < 5; i++) { if (slotInfo[i].attachedType == -1) { slotAnimators[i].enabled = false; } } } else if (objectInHand.GetComponent <VRSlider>()) // call to update ststs { objectInHand.GetComponent <Rigidbody>().isKinematic = true; objectInHand.GetComponent <VRSlider>().Exit(); } else if (objectInHand.GetComponent <HourglassControl>()) // call horglass back to belt { objectInHand.GetComponent <HourglassControl>().CallReturnToBelt(); objectInHand.GetComponent <Rigidbody>().isKinematic = true; objectInHand.GetComponent <HourglassControl>().interactable = false; } else // throw other objects with normal velocity { objectInHand.GetComponent <Rigidbody>().velocity = controllerPose.GetVelocity(); objectInHand.GetComponent <Rigidbody>().angularVelocity = controllerPose.GetAngularVelocity(); } } }