Beispiel #1
0
    void ChangeWeapon(Guns weapon)
    {
        if (_inventory.HaveGun[(int)weapon])
        {
            //Switch to the correct gun in the inventory
            switch (weapon)
            {
            case Guns.Knife:
                _inventory.CurrentGun = Guns.Knife;
                break;

            case Guns.Pistol:
                _inventory.CurrentGun = Guns.Pistol;
                break;

            case Guns.Shotgun:
                _inventory.CurrentGun = Guns.Shotgun;
                break;

            case Guns.Rifle:
                _inventory.CurrentGun = Guns.Rifle;
                break;

            case Guns.RocketLauncher:
                _inventory.CurrentGun = Guns.RocketLauncher;
                break;
            }

            //Change the bullet and fire rate
            _gunController.ChangeBullet(_inventory.AmmoPrefab[(int)weapon]);
            _gunController.ChangeTimer(_inventory.FireTimer[(int)weapon]);
            _gunController.ChangeAudioClip(_inventory.AudioClips[(int)weapon]);

            //Switch to the correct weapon mesh
            _currentGun.SetActive(false);
            _currentGun = _gunObjects[(int)weapon];
            _currentGun.SetActive(true);

            UpdateAmmoText();

            FindObjectOfType <AudioManager>().Play("ChangeWeapon");
        }
    }