Exemplo n.º 1
0
        private IEnumerator AttackPatternLoop(AttackPatternType pattern, float timeBeforeStarting)
        {
            yield return(new WaitForSeconds(timeBeforeStarting));

            while (true)
            {
                int        currentStep = _currentSteps[pattern];
                AttackStep attackStep  = AttackPatterns.GetNextAttackStep(pattern, currentStep);
                foreach (ProjectileAttack attack in attackStep.ProjectileAttacks)
                {
                    GameObject       prefab           = _prefabs[attack.Type];
                    Vector2          trajectory       = attack.Trajectory.magnitude == 0f ? GetTrajectoryTowardsPlayer() : attack.Trajectory;
                    GameObject       projectile       = Instantiate(prefab, _transform.position, LookRotation2D(trajectory), _bulletContainer);
                    ProjectileScript projectileScript = projectile.GetComponent <ProjectileScript>();

                    projectileScript.Initialize(playSpawnSound: attack.PlayAudio);
                }

                _currentSteps[pattern]++;
                yield return(new WaitForSeconds(attackStep.StepDelay));
            }
            // ReSharper disable once IteratorNeverReturns
        }