Exemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            if (anchorTarget)
            {
                float dist = Vector3.Distance(anchorTarget.transform.position, transform.position);
                if (dist >= pullDist)
                {
                    InteractionBehaviour targetInteraction = anchorTarget.GetComponent <InteractionBehaviour>();
                    targetInteraction.OnGraspEnd   -= OnGraspEnd;
                    targetInteraction.OnGraspBegin -= OnGraspBegin;

                    // clone stuff, manage attachment
                    GameObject           clone            = GameObject.Instantiate(anchorTarget, anchorTarget.transform.parent);
                    InteractionBehaviour cloneInteraction = clone.GetComponent <InteractionBehaviour>();
                    cloneInteraction.OnGraspEnd   += OnGraspEnd;
                    cloneInteraction.OnGraspBegin += OnGraspBegin;

                    // enable our anchor
                    anchor.enabled = true;
                    InteractionBehaviour interaction = clone.GetComponent <InteractionBehaviour>();
                    AnchorableBehaviour  anchorable  = clone.GetComponent <AnchorableBehaviour>();
                    //anchorable.transform.SetPositionAndRotation(anchor.transform.position, anchor.transform.rotation);
                    interaction.rigidbody.position = transform.position;
                    interaction.rigidbody.rotation = transform.rotation;

                    anchorable.anchor = anchor;
                    anchorable.TryAttach(true);
                    anchorTarget = clone.gameObject;
                }
            }
        }
Exemplo n.º 2
0
        void OnGraspEnd()
        {
            // return item to slot!
            anchor.enabled = true;
            AnchorableBehaviour anchorable = anchorTarget.GetComponent <AnchorableBehaviour>();

            anchorable.anchor = anchor;
            anchorable.TryAttach(true);
        }