private bool PickupClosest() { PickableItem closest = null; float closestDistance = float.MaxValue; foreach (var hovering in connectedHand.CurrentlyHoveringOver) { if (hovering.Key == null) { continue; } float distance = Vector3.Distance(this.transform.position, hovering.Key.transform.position); if (distance < closestDistance) { closestDistance = distance; if (hovering.Key.GetType() == typeof(PickableItem)) { closest = (PickableItem)hovering.Key; } } } if (closest != null) { connectedHand.EndInteraction(closest); AddToInventory(closest); inventorySound.Play(); return(true); } else { return(false); } }
void Update() { if (swordUI.FireIsDepleted()) { return; } if (attachedGun.gameObject.activeSelf) { return; } if (attachedHand.HoldButtonDown) { if (attachedHand.CurrentlyInteracting == null) { VibrateController(); PrepareShuriken(); attachedHand.BeginInteraction(instantiatedShuriken.GetComponent <NVRInteractableItem>()); } } else if (attachedHand.HoldButtonUp) { if (attachedHand.CurrentlyInteracting != null) { if (attachedHand.CurrentlyInteracting.gameObject.CompareTag("Shuriken")) { if (instantiatedShuriken != null) { if (attachedHand.CurrentlyInteracting == instantiatedShuriken.GetComponent <NVRInteractableItem>()) { VibrateController(); attachedHand.EndInteraction(instantiatedShuriken.GetComponent <NVRInteractableItem>()); swordUI.DepleteFire(usageCost); instantiatedShuriken.GetComponent <Rigidbody>().AddForce(instantiatedShuriken.GetComponent <Rigidbody>().velocity.normalized); instantiatedShuriken.GetComponent <Shuriken>().SetThrown(true); PlayShurikenNoise(); StartCoroutine("ShootShurikens"); StartCoroutine("ShootWaitTime"); } } } } } }
/* * snapToBolt - * Tool colliding with bolt snaps to bolts position with offset. * NVR Hand and NVR interactable item functionality is disbaled so only RatchetRotation affects tool. * Set bolt's parent to the tool * Swich Colliders to sphere collider * */ public void ToolSnapToBolt(Collider col) { if (CheckToolAndBoltStateForSnap(col)) { if (col.gameObject.GetComponent <Bolt_NVR>().partSize == this.gameObject.GetComponent <Tool>().toolSize) { col.gameObject.GetComponent <Bolt_NVR>().snappedTool = this.gameObject; toolInRotationMode = true; snappedObject = col.gameObject; if (OnToolSnappedToBoltEvent != null) { Debug.Log("we are oion "); //OnToolSnappedToBoltEvent(this, snappedObject); } NVRInteractableItem interactableItem = this.gameObject.GetComponent <NVRInteractableItem>(); interactingControllerRM = interactableItem.AttachedHand.gameObject; // turn off the NVRHand on this controller // turn off the hand on this controller NVRHand hand = interactableItem.AttachedHand.GetComponent <NVRHand>(); hand.EndInteraction(interactableItem); hand.enabled = false; interactableItem.EndInteraction(hand); interactableItem.enabled = false; interactingControllerRM.gameObject.GetComponent <RotationHand_NVR>().currentRotationTool = this.gameObject; //Switch Colliders this.gameObject.GetComponent <SphereCollider>().enabled = true; this.gameObject.GetComponent <CapsuleCollider>().enabled = false; //Set the position of the tool to the bolt this.gameObject.transform.position = col.transform.position + col.gameObject.GetComponent <Bolt_NVR>().offsetToolAttach; Quaternion Q = new Quaternion(); Q.eulerAngles = new Vector3(0f, this.transform.rotation.eulerAngles.y, 0f) + snapRotationOffset; this.gameObject.transform.rotation = Q; this.GetComponent <Rigidbody>().velocity = Vector3.zero; this.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; Debug.Log("Finsihsed snapping"); } } }
internal void DeleteObjectAt(NVRHand hand) { Debug.Log("Deleting object interacting with " + hand); if (hand.IsInteracting) { //DebugSphere(hand.CurrentlyInteracting, "Interacting with"); NodeObject sphere = hand.CurrentlyInteracting.GetComponent <NodeObject>(); if (sphere == null) { Debug.Log("Hand is interacting with something that is not a NodeObject: " + hand.CurrentlyInteracting); } else { Debug.Log("Deleting sphere " + sphere); hand.EndInteraction(hand.CurrentlyInteracting); sphere.Detach(); Destroy(sphere.gameObject, 0.1f); } } else if (hand.IsHovering) { Debug.Log("No interacting object, but hand is hovering"); } }