예제 #1
0
    private void Update()
    {
        //Checks if the player owns this gun
        bool ownsGun = gameManager.player.guns.Contains(gun);//gameManager.player._gun.Equals(gun);

        //Update the purchase UI
        if (insideBuyArea)
        {
            gameManager.UpdatePurchaseInfo(gun, ownsGun, insideBuyArea);
        }
        //Checks if the player is pressing the b key and there is no delay and is inside the area
        if (Input.GetKeyDown(KeyCode.B) && buyDelay <= 0 && insideBuyArea)
        {
            //Checks if the player owns the gun and has the money to purchase the ammo
            if (ownsGun && gameManager.player.money >= gun.AmmoPrice())
            {
                Gun playerGun = gameManager.player.GetGun(gun);
                //Reset the guns ammo (sets the current clip and reserve ammo)
                playerGun.Reset();
                //Updates the bullets UI
                gameManager.UpdateBullets(playerGun);
                //Updates the money UI and removes the money from the player
                gameManager.UpdateMoney(-gun.AmmoPrice());
                //Checks if the player is reloading a gun
                if (gameManager.player.reloadingGun)
                {
                    //Reset reload of the gun
                    playerGun.ResetReload();
                    //Current colors of the sprite
                    Color color = gameManager.gunImage.color;
                    gameManager.gunImage.color = new Color(color.r, color.g, color.b, playerGun.maxOpcity);
                }
                feedback.DisplayFeedback($"You successfully purchased the ammo for the {gun.WeaponName()} for ${gun.AmmoPrice()}.");
            }
            //Checks if the player does not own the gun and has the price to buy the weapon
            else if (!ownsGun && gameManager.player.money >= gun.BuyPrice())
            {
                if (gameManager.player.HasBothGuns())
                {
                    gameManager.player.SwapGun(gun.WeaponName());
                }
                else
                {
                    gameManager.player.guns[1] = gun;
                    gameManager.player.SwitchGun();
                }
                //Makes the player switch to the weapon he bought
                //
                //Updates the money UI and removes the money from the player
                gameManager.UpdateMoney(-gun.BuyPrice());
                feedback.DisplayFeedback($"You successfully purchased the {gun.WeaponName()} for ${gun.BuyPrice()}.");
            }
            else
            {
                feedback.DisplayFeedback(ownsGun ? $"Not enough money, you need at least ${gun.AmmoPrice()} to purchase the ammo for the {gun.WeaponName()}" : $"Not enough money, you need at least ${gun.BuyPrice()} to purchase the {gun.WeaponName()}.");
            }
            //Sets the delay for the b key
            buyDelay = 1.5f;
        }

        //Checks if there is currently a delay for buying a weapon or ammo
        if (buyDelay > 0)
        {
            //Decreases the delay
            buyDelay -= Time.deltaTime;
        }
    }
예제 #2
0
 public void UpdatePurchaseInfo(Gun gun, bool ownsGun, bool inside = false)
 {
     //Sets the purchase text in the game UI
     purchaseText.text = !inside ? "" : ownsGun ? $"Press B to buy full ammo for the\n\n{gun.WeaponName()} for ${gun.AmmoPrice()}" : $"Press B to buy\n\n{gun.WeaponName()} for ${gun.BuyPrice()}";
     //Sets the sprite of the purchase info
     purchaseGunImage.sprite = gun.gunSprite;
     //Unhides the gun image
     purchaseGunImage.gameObject.SetActive(inside);
     //Hides or unhides the purchase text object
     purchaseText.gameObject.SetActive(inside);
 }