Exemple #1
0
    public void BuyPriAmmo()
    {
        PlayerWeapons   weapon  = playerWeapon.GetComponent <PlayerWeapons>();
        BulletInventory bullets = playerWeapon.GetComponent <BulletInventory>();

        if (bullets.GetPriTotalBullets() < bullets.GetPriMaxTotalBullets())
        {
            int BulletsToBuy = bullets.GetPriMaxTotalBullets() - bullets.GetPriTotalBullets();
            int CashNeeded   = 20 * BulletsToBuy;

            // if hvae enough money to fill up to max total bullets
            if (weapon.GetCash() >= CashNeeded)
            {
                weapon.AddCash(-CashNeeded);
                bullets.SetPriTotalBullets(bullets.GetPriMaxTotalBullets());
            }
            else
            {
                // Not enough money to buy all of the "needed to fill up to max total bullets"
                // So we buy until have no money
                int BulletsICanBuy = weapon.GetCash() / 20;

                weapon.AddCash(-(BulletsICanBuy * 20));
                bullets.SetPriTotalBullets(bullets.GetPriTotalBullets() + BulletsICanBuy);
            }
        }
    }
Exemple #2
0
    public void SetPriWeapon(string PriWeapon)
    {
        if (primaryWeapon != "None" && primaryWeapon == PriWeapon)
        {
            return;
        }
        else
        {
            primaryWeapon = PriWeapon;
            BulletInventory bullets = GetComponent <BulletInventory>();
            bullets.SetPriCurrBullets(30);
            bullets.SetPriTotalBullets(0);
            bullets.SetPriMaxBullets(30);
            bullets.SetPriMaxTotalBullets(90);

            if (currWepType == "Primary")
            {
                if (primaryWeapon == "AK-47")
                {
                    weaponImage.sprite = AKImage;
                }
                else if (primaryWeapon == "M4A1")
                {
                    weaponImage.sprite = M4Image;
                }
            }
        }
    }