protected virtual void Shoot()
    {
        float angle      = Random.Range(-bulletDeviation, bulletDeviation);
        float deltaAngle = spread / (bulletAmount + 1);

        for (int i = 1; i <= bulletAmount; i++)
        {
            Vector3 rot = bulletSpawn.rotation.eulerAngles;
            rot.z += angle + spread / 2f - (deltaAngle * i);

            // Execute shooting behaviour.
            _shootingBehaviour.Activate(bulletSpawn.position, Quaternion.Euler(rot));

            ////////// OLD SPAWN CODE //////////

            // GameObject bullet = Instantiate(bulletPrefab, bulletSpawn.position, Quaternion.Euler(rot)) as GameObject;

            // // Check if the assigned bullet is a bullet itself or a bullet container
            // if (bullet.GetComponent<BulletBase>() == null)
            // {
            //     foreach (BulletBase childBullet in bullet.GetComponentsInChildren<BulletBase>())
            //     {
            //         SpawnBullet(childBullet.gameObject);
            //     }
            // }
            // else
            // {
            //     SpawnBullet(bullet);
            // }
        }
    }
Esempio n. 2
0
        public void Initialize()
        {
            foreach (var weapon in _weapons)
            {
                weapon.Initialize();
            }

            _currentWeapon = _weapons[_pointer];
            _currentWeapon.Activate();
        }
Esempio n. 3
0
        private void ChangeWeapon(int changeIndex)
        {
            _pointer += changeIndex;
            if (_pointer < 0)
            {
                _pointer = _weapons.Count - _pointer;
            }
            if (_pointer >= _weapons.Count)
            {
                _pointer -= _weapons.Count;
            }

            _currentWeapon.Deactivate();
            _currentWeapon = _weapons[_pointer];
            _currentWeapon.Activate();
        }