Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weapon"></param>
        /// <param name="spawnPickable"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool ClearWeapon(WeaponEquippable weapon, bool spawnPickable = true, int index = -1)
        {
            if (index == -1)
            {
                for (var i = 0; i < _weapons.Length; ++i)
                {
                    if (_weapons[i] == weapon)
                    {
                        index = i;
                    }
                }

                Debug.Assert(index >= 0);
            }

            var switchWeapon = _currentEquippable is WeaponEquippable;

            Destroy(weapon.gameObject);
            if (spawnPickable && weapon.weaponDescriptor != spawner.defaultWeapon)
            {
                GameplayStatics.SpawnWeaponPickable(weapon.weaponDescriptor, transform.position);
            }

            _weapons[index] = null;

            if (switchWeapon)
            {
                _currentEquippable = null;
                SwitchWeapon();
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weaponPrefab"></param>
        /// <returns></returns>
        public WeaponEquippable SetWeapon(int index, WeaponEquippable weaponPrefab)
        {
            Debug.Assert(weaponPrefab != null);
            Debug.Assert(index >= 0 && index < MaxWeaponsNumber);

            if (_weapons[index] != null)
            {
                Destroy(_weapons[index].gameObject);
            }

            var characterInput = GetComponent <CharacterInput>();

            if (currentEquippable != null && characterInput != null && characterInput.isFiring)
            {
                _weapons[index] = weaponPrefab;
                weaponPrefab.spriteRenderer.enabled = false;
            }
            else
            {
                _weapons[index]  = SetEquippable(weaponPrefab) as WeaponEquippable;
                _lastWeaponIndex = index;
            }
            return(_weapons[index]);
        }