Beispiel #1
0
    void HandleHand(EquipmentSlot slot, bool down, bool interact)
    {
        if (slot.occupied) {
            var item = slot.item;
            if (down && interact && item.CanUnequip(slot)) {
                slot.Unequip();
                item.OnDrop();
                item.GetComponent<Rigidbody>().AddForce(
                    (Vector3.up + _camera.transform.forward) * 200.0f);
            }
        } else if (down) {
            Item highlightedItem = null;

            var pos = slot.attachment.transform.position;
            var distance = pickupRange;
            var colliders = Physics.OverlapSphere(pos, pickupRange);

            foreach (var col in colliders) {
                var item = col.GetComponentInParent<Item>();
                if ((item == null) || item.equipped ||
                    !item.CanEquip(slot)) continue;

                var dis = Vector3.Distance(pos, col.ClosestPointOnBounds(pos));
                if (dis <= distance) {
                    highlightedItem = item;
                    distance = dis;
                }
            }

            if (highlightedItem != null) {
                highlightedItem.highlighted = true;

                if (interact) {
                    highlightedItem.OnPickup();
                    slot.Equip(highlightedItem);
                }
            }
        }
    }