pickUp() public méthode

public pickUp ( ) : void
Résultat void
    /// <summary>
    /// Picks up the closest item in range.
    /// </summary>
    protected void pickupItem()
    {
        Collider2D[] itemsInRange   = Physics2D.OverlapCircleAll(transform.position, 2f, pickableItems);
        int          nearestItem    = 0;
        float        lowestDistance = 1000f;

        if (itemsInRange.Length > 0)
        {
            int totalItems = itemsInRange.Length;
            for (int i = 0; i < totalItems; i++)
            {
                float distance = Vector2.Distance(transform.position, itemsInRange[i].transform.position);
                if (distance < lowestDistance)
                {
                    lowestDistance = distance;
                    nearestItem    = i;
                }
            }
            grabbedItem = itemsInRange[nearestItem].GetComponent <PickableItem>();
            if (!grabbedItem.getIsUsed() && !grabbedItem.getIsPicked())
            {
                hasItem = true;
                grabbedItem.setIsUsed(false);
                grabbedItem.setIsPicked(true);
                grabbedItem.pickUp(pickUpSpot);
            }
        }
    }
Exemple #2
0
    void managePickUp(Collider col)
    {
        PickableItem item = col.GetComponent <PickableItem>();

        if (null != item)
        {
            Logger.Log("Hero::managePickUp collided with DNA! bit=" + item.getDNABit(), Logger.Level.INFO);
            item.pickUp();
            RedMetricsManager.get().sendEvent(TrackingEvent.PICKUP, new CustomData(CustomDataTag.DNABIT, item.getDNABit().getInternalName()));
        }
    }