コード例 #1
0
    public void SwapItems(int slot, Transform obj = null)
    {
        if (interactControl)
        {
            Transform otherItem;
            if (!obj)
            {
                otherItem = interactControl.rightGrab;
            }
            else
            {
                otherItem = obj;
            }
            Transform            slotItem = slots[slot];
            string               tempTag  = tags[slot];
            RigidbodyConstraints rc       = rigidbodyConstraints[slot];

            if (otherItem)
            {
                if (!obj)
                {
                    interactControl.ReleaseHand(true, false);
                }
                SetItemToSlot(otherItem, slot);
                StartCoroutine(ChangePosOverTime(otherItem, slotsPos[slot], 10f));
            }
            else
            {
                slots[slot] = null;
            }
            if (slotItem)
            {
                Debug.Log("slot filled");
                slotItem.tag = (tempTag != null && tempTag != "") ? tempTag : "Item";
                slotItem.SetParent(null);
                slotItem.GetComponent <Rigidbody>().constraints = rc;
                MessageArgs msg = new MessageArgs(transform);
                slotItem.SendMessage("OnInventoryRelease", msg, SendMessageOptions.DontRequireReceiver);
                if (!msg.received)
                {
                    if (!interactControl.rightHandGrabbing)
                    {
                        interactControl.GrabItem(slotItem, true);
                    }
                }
            }
        }
    }
コード例 #2
0
    void OnThrow(MessageArgs msg)
    {
        msg.received = true;
        InteractControl i = msg.sender.GetComponent <InteractControl>();

        if (i)
        {
            if (i.IsHuman)
            {
                i.ReleaseHand(true, false, true);
                rig.AddForce(i.throwingAngle * i.throwPower * i.throwForce, ForceMode.Impulse);
                rig.maxAngularVelocity = maxAngVel;
                flyingWithSpin         = true;
            }
        }
        //rig.AddTorque(spinForce * transform.right, ForceMode.Acceleration);
    }
コード例 #3
0
    bool GetOnLadder(Transform t)
    {
        bool success = false;

        RaycastHit[] hits = Physics.RaycastAll(t.position, t.forward, 2);
        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].transform == transform)
            {
                success = true;
                InteractControl interactControl = t.GetComponent <InteractControl>();
                if (interactControl)
                {
                    interactControl.ReleaseHand();
                    interactControl.rightGrab         = transform;
                    interactControl.leftGrab          = transform;
                    interactControl.rightHandGrabbing = true;
                    interactControl.leftHandGrabbing  = true;

                    interactControl.rigidbodyConstraints[0] = GetComponent <Rigidbody>().constraints;
                }

                ladderPoint.position = new Vector3(hits[i].point.x + ladderPoint.localPosition.z, hits[i].point.y, ladderPoint.position.z);
                onLadder             = true;
                user = t;

                if (t.GetComponent <PlayerMovement>())
                {
                    t.GetComponent <PlayerMovement>().enabled = false;
                }

                gameObject.layer = LayerMask.NameToLayer("IgnorePlayer");

                t.rotation = Quaternion.LookRotation(transform.forward);
                Debug.Log("GettingOnLadder");
                Debug.DrawRay(transform.position, transform.forward, Color.black, 3f);
            }
        }
        return(success);
    }