public bool Throw(Vector3 velocity, bool local = true, bool networked = false) { if (!is_grabbed) { return(false); } if (local) { velocity = parent.transform.TransformDirection(velocity); } if (!networked) { transform.parent = previous_transform; } else { NetworkedObjectTransform networkedTransform = GetComponent <NetworkedObjectTransform>(); if (networkedTransform != null) { networkedTransform.networkParent = previous_network_transform; } } SetThrownState(); rigidbody.AddForce(velocity, ForceMode.VelocityChange); return(true); }
public bool Pickup(GameObject grabber, Vector3 grab_offset = default(Vector3), bool networked = false) { if (is_grabbed) { return(false); } if (!networked) { previous_transform = transform.parent; if (grabber.transform.parent.parent == transform) { grabber.transform.parent.parent = transform.parent; } transform.parent = grabber.transform; transform.localPosition = grab_offset; transform.localRotation = Quaternion.identity; } else { NetworkedObjectTransform networkedTransform = GetComponent <NetworkedObjectTransform>(); NetworkedObjectTransform grabberNetworkedTransform = grabber.GetComponent <NetworkedObjectTransform>(); if (networkedTransform != null && grabberNetworkedTransform != null) { previous_network_transform = networkedTransform.networkParent; if (grabberNetworkedTransform.networkParent == networkedTransform) { grabberNetworkedTransform.networkParent = networkedTransform.networkParent; } networkedTransform.networkParent = grabberNetworkedTransform; networkedTransform.networkParentLocalPosition = grab_offset; networkedTransform.networkParentLocalRotation = Quaternion.identity; } } SetPickupState(grabber); return(true); }