Beispiel #1
0
    public IEnumerator BurstFire()
    {
        yield return(new WaitForSeconds(0.1f));

        // rate of fire in weapons is in rounds per minute (RPM), therefore we should calculate how much time passes before firing a new round in the same burst.

        //Looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.playDefaultSoundEffect();
        }

        for (int i = 0; i < nbrShots; i++)
        {
            //Mono sound effect
            if (!soundEffectsGenerator.isLooping)
            {
                soundEffectsGenerator.playDefaultSoundEffect();
            }

            //Calculate angle
            float angle = 0;
            if (targetingType == TargetingType.circle)
            {
                angle = angleViseur + 90 + Random.Range(-precisionFactor, precisionFactor);
            }
            else if (targetingType == TargetingType.front)
            {
                angle = -90 + Random.Range(-precisionFactor, precisionFactor);
            }

            //Calculate position
            Vector3 bulletPosition = new Vector3(transform.position.x, transform.position.y, 1);

            //Generate salve object
            Salve salve = new Salve();
            salve = pooler.getSalve();
            salve.transform.position = bulletPosition;
            salve.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
            salve.gameObject.SetActive(true);
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].transform.localPosition = salve.projectilesInitialPosition[j];
                salve.projectiles[j].transform.localRotation = salve.projectilesInitialRotation[j];
                salve.projectiles[j].gameObject.SetActive(true);
                salve.projectiles[j].col.enabled = true;
            }

            //Initiate object stats
            salve.globalDamage      = globalDamage;
            salve.globalHealth      = globalHealth;
            salve.globalBulletSpeed = globalBulletSpeed;
            for (int j = 0; j < salve.projectiles.Length; j++)
            {
                salve.projectiles[j].damage      = globalDamage;
                salve.projectiles[j].health      = globalHealth;
                salve.projectiles[j].bulletSpeed = globalBulletSpeed;
            }

            yield return(new WaitForSeconds(fireRate)); // wait till the next round
        }

        //Stop looping sound effect
        if (soundEffectsGenerator.isLooping)
        {
            soundEffectsGenerator.stopSoundEffect();
        }

        ennemy.isMoving = true;
        isFiring        = false;
        cooldownTimer   = cooldown;
    }