Exemple #1
0
    void CheckSwitching()
    {
        float inventoryLength = 0;

        for (int i = 0; i < toolInventory.Length; i++)
        {
            if (toolInventory[i] != null)
            {
                inventoryLength += 1;
            }
        }


        if (Input.GetButtonDown(switchGunUpButton))
        {
            if (equippedItem + 1 < inventoryLength)
            {
                if (toolInventory[equippedItem + 1] != null)
                {
                    equippedItem += 1;
                }
            }
            else
            {
                equippedItem = 0;
            }
        }

        if (Input.GetButtonDown(switchGunDownButton))
        {
            if (equippedItem - 1 >= 0)
            {
                if (toolInventory[equippedItem - 1] != null)
                {
                    equippedItem -= 1;
                }
            }
            else
            {
                equippedItem = (int)inventoryLength - 1;
            }
        }
        gunn          = gun.GetComponent <Destructible2D.D2dGun>();
        currentWeapon = toolInventory[equippedItem].GetComponent <StructHolder>();
        anim.runtimeAnimatorController = currentWeapon.weaponData.animationController;
    }