public void DetachFromHand(VRHand hand, Transform newParent = null)
        {
            if (!isHeld)
            {
                Debug.LogAssertion(gameObject.name + ": Trying to detach a deteached pickup");
                return;
            }
            if (hand != attachedHand || hand == null)
            {
                Debug.LogAssertion(gameObject.name + ": Trying to detach pickup from a wrong or null hand");
                return;
            }
            if (!hand.RequestDetachFromHand(this))
            {
                Debug.LogError(gameObject.name + ": Error during detaching pickup from hand");
                return;
            }
            switch (lockPolicy)
            {
            case LockPolicy.Transform:
                transform.parent = newParent;
                break;

            case LockPolicy.Joint:
                Destroy(joint);
                joint = null;
                break;
            }
            if (rigid)
            {
                rigid.isKinematic = oldIsKinematic;
                VelocityEstimator ve = GetComponent <VelocityEstimator>();
                if (ve)
                {
                    rigid.velocity        = ve.estimatedVelocity;
                    rigid.angularVelocity = ve.estimatedAngularVelocity;
                }
            }
            foreach (var h in GetComponentsInChildren <Collider>())
            {
                if (!h.isTrigger)
                {
                    hand.collisionManager.UnregisterCollider(h);
                }
            }
            m_attachedHand = null;
            gameObject.BroadcastMessage("OnDetachFromHand", hand, SendMessageOptions.DontRequireReceiver);
        }
Beispiel #2
0
 void Start()
 {
     StartCoroutine(ClearRecord());
     ve = GetComponent <VelocityEstimator>();
 }