Exemple #1
0
    public void ReloadCurrBullets()
    {
        soundEffectSource        = soundEffectSound.GetComponent <AudioSource>();
        soundEffectSource.volume = PlayerPrefs.GetFloat("sfxVol", 1);

        BulletInventory bullets = GetComponent <BulletInventory>();
        PlayerWeapons   weapons = GetComponent <PlayerWeapons>();

        if (Time.timeScale == 0.0f) // if  paused, return
        {
            return;
        }

        if (weapons.GetCurrWeaponType() == "Primary")
        {
            // Check if need to reload
            if (bullets.GetPriCurrBullets() < bullets.GetPriMaxBullets())
            {
                // How many bullets to load
                int BulletsToLoad = bullets.GetPriMaxBullets() - bullets.GetPriCurrBullets();

                if (bullets.GetPriTotalBullets() > 0)
                {
                    if (BulletsToLoad <= bullets.GetPriTotalBullets())
                    {
                        soundEffectSource.Play();

                        bullets.SetPriCurrBullets(bullets.GetPriMaxBullets());
                        bullets.AddPriTotalBullets(-BulletsToLoad);
                    }
                    else
                    {
                        soundEffectSource.Play();

                        bullets.SetPriCurrBullets(bullets.GetPriCurrBullets() + bullets.GetPriTotalBullets());
                        bullets.AddPriTotalBullets(-(bullets.GetPriTotalBullets()));
                    }
                }
                else
                {
                    //play another sound
                }
            }
        }
        else if (weapons.GetCurrWeaponType() == "Secondary")
        {
            // Check if need to reload
            if (bullets.GetSecCurrBullets() < bullets.GetSecMaxBullets())
            {
                // How many bullets to load
                int BulletsToLoad = bullets.GetSecMaxBullets() - bullets.GetSecCurrBullets();

                if (bullets.GetSecTotalBullets() > 0)
                {
                    if (BulletsToLoad <= bullets.GetSecTotalBullets())
                    {
                        soundEffectSource.Play();

                        bullets.SetSecCurrBullets(bullets.GetSecMaxBullets());
                        bullets.AddSecTotalBullets(-BulletsToLoad);
                    }
                    else
                    {
                        soundEffectSource.Play();

                        bullets.SetSecCurrBullets(bullets.GetSecCurrBullets() + bullets.GetSecTotalBullets());
                        bullets.AddSecTotalBullets(-(bullets.GetSecTotalBullets()));
                    }
                }
                else
                {
                    // Do not play sound / Play another sound
                }
            }
        }
    }