public void Pickup() { // Get nearest interactable currentInteractable = GetNearestInteractable(); // Null check if (!currentInteractable) { return; } // check if kinematic or physics based if (currentInteractable.GetComponent <Rigidbody>().isKinematic) { currentInteractable.transform.parent = this.transform; } else { // Position currentInteractable.ApplyOffset(transform); // Attach Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>(); joint.connectedBody = targetBody; } // Set active hand currentInteractable.activeHand = this; currentInteractable.OnPickup(this); }
public void Drop() { // Null check if (!currentInteractable) { return; } // Method called before drop currentInteractable.OnDrop(this); // check if kinematic or physics based if (currentInteractable.GetComponent <Rigidbody>().isKinematic) { currentInteractable.transform.parent = null; } else { // Apply velocity Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>(); targetBody.velocity = pose.GetVelocity(); targetBody.angularVelocity = pose.GetAngularVelocity(); // Detach joint.connectedBody = null; } // Clear active hand currentInteractable.activeHand = null; currentInteractable = null; }
public void Interact() { if (MyInteractable != null) { MyInteractable.Interact(); } }
public void Pickup() { // Get nearest interactable currentInteractable = GetNearestInteractable(); // Null check if (!currentInteractable) { return; } // Already held, check if (currentInteractable.m_ActiveHand) { currentInteractable.m_ActiveHand.Drop(); } // Position currentInteractable.ApplyOffset(transform); // Attach Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>(); joint.connectedBody = targetBody; // Set active hand currentInteractable.m_ActiveHand = this; currentInteractable.OnPickup(this); }
private void OnTriggerExit(Collider other) { if (other.gameObject.GetComponent <MyInteractable>() != null) { interactable = null; } }
private void OnTriggerExit2D(Collider2D collision) { if (collision.tag == "Enemy" || collision.tag == "Interactable") { if (MyInteractable != null) { MyInteractable.StopInteract(); MyInteractable = null; } } }
public void Close() { pageIndex = 0; pages.Clear(); canvasGroup.alpha = 0; canvasGroup.blocksRaycasts = false; ClearButtons(); if (MyInteractable != null) { MyInteractable.StopInteract(); } MyInteractable = null; }
private MyInteractable GetNearestInteractable() { MyInteractable nearest = null; float minDistance = float.MaxValue; float distance = 0.0f; foreach (MyInteractable interactable in inRangeInteractables) { distance = (interactable.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; nearest = interactable; } } return(nearest); }
public void Drop() { // Null check if (!currentInteractable) { return; } // Method called before drop currentInteractable.OnDrop(this); // Apply velocity Rigidbody targetBody = currentInteractable.GetComponent <Rigidbody>(); targetBody.velocity = pose.GetVelocity(); targetBody.angularVelocity = pose.GetAngularVelocity(); // Detach joint.connectedBody = null; // Clear currentInteractable.m_ActiveHand = null; currentInteractable = null; }