Inventory.getPositionOfItem C# (CSharp) Method

getPositionOfItem() public method

public getPositionOfItem ( Item item ) : int
item Item
return int
    public int getPositionOfItem(Item item)
    {
        for (int i = 0; i < SlotContainer.transform.childCount; i++)
        {
            if (SlotContainer.transform.GetChild(i).childCount != 0)
            {
                Item item2 = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent<ItemOnObject>().item;
                if (item.Equals(item2))
                    return i;
            }
        }
        return -1;
    }

Usage Example

Ejemplo n.º 1
0
    void Update()
    {
        if (itemBeingAimed == null)
        {
            return;                         //If there is no item being aimed, don't do anything.
        }
        //Try to find a point on the map the player is aiming at, and do nothing if it does not exist.
        Vector3 aimPoint = GetAimPoint();

        if (aimPoint.Equals(Vector3.positiveInfinity))
        {
            return;
        }

        itemBeingAimed.VisualiseAim(userTransform, aimPoint);

        //When the user releases the mouse button again, fire the item, stop aiming, and unlock the camera.
        if (Input.GetMouseButtonUp(0))
        {
            player.Fire();
            itemBeingAimedInventory.StartCooldown(itemBeingAimedInventory.getPositionOfItem(itemBeingAimed));
            StartCoroutine(WaitThenFire(aimPoint));
        }
    }