Пример #1
0
    public override void OnGrab(Grabber grabber, Transform pivot)
    {
        //Check if we can even grab this object
        if (excludeTags.Length > 0)
        {
            MultiTag objTags = grabber.GetComponent <MultiTag>();

            if (objTags != null)
            {
                foreach (var tag in excludeTags)
                {
                    if (objTags.ContainsTag(tag))
                    {
                        return;
                    }
                }
            }
        }

        //Is this item is already grabbed, check if we can grab the parent
        if (isGrabbed)
        {
            if (allowGrabbingParent)
            {
                Grabbable parent = grabParent.GetComponent <Grabbable>();

                if (parent != null)
                {
                    parent.OnGrab(grabber, pivot);
                    return;
                }
            }
            else
            {
                return;
            }
        }

        //Attach the object to the grabber
        rigidbody.isKinematic = true;
        transform.position    = pivot.position;
        transform.parent      = pivot;

        if (useCustomRotation)
        {
            transform.localRotation = Quaternion.Euler(grabRotation);
        }

        joint = gameObject.AddComponent <FixedJoint>();
        joint.connectedBody = grabber.rigidbody;

        Helper.ChangeLayerRecursively(transform, LayerMask.NameToLayer(ignoreCollisionlayerName));
        ChangeCollisionDetectionfItem(grabber, true);

        grabParent = grabber;
        grabber.grabbedItens.Add(this);
        RaiseOnGrabEvent();
    }
Пример #2
0
    private void Grabbable_onGrab(Grabber obj)
    {
        if (isEmpty)
        {
            return;
        }

        MultiTag objTags = obj.GetComponent <MultiTag>();

        if (objTags == null || !objTags.ContainsTag(stickTag))
        {
            return;
        }

        isEmpty = true;
        effect.SetActive(true);
    }