public override IEnumerator Attack(Player player)
    {
        isAttacking = true;
        // Attack timer stays constant even if the enemy disengages
        while (isAttacking)
        {
            attackTimer += Time.deltaTime;
            if (attackTimer >= timeBetweenAttacks)
            {
                for (int i = 0; i < bulletsPerShot; i++)
                {
                    var instantiatedBullet    = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation);
                    var targetVelocity        = Target.GetComponent <Rigidbody>().velocity;
                    var updatedTargetPosition = Target.position + targetVelocity * 0.5f;
                    updatedTargetPosition.y += 1.5f;
                    instantiatedBullet.GetComponent <Rigidbody>().velocity = (updatedTargetPosition - bulletEmitter.transform.position).normalized * 30 + CalculateSpread(transform);
                    var bulletScript = instantiatedBullet.GetComponent <Bullet>();
                    bulletScript.IsFriendly = false;
                    instantiatedBullet.transform.localScale *= 3;
                }

                attackTimer           = 0.0f;
                EnemyAudioSource.clip = ShootingNoise;
                EnemyAudioSource.Play();
            }
            yield return(null);
        }
    }
Esempio n. 2
0
    public override IEnumerator Attack(Player player)
    {
        isAttacking = true;
        // Attack timer stays constant even if the enemy disengages
        while (isAttacking)
        {
            attackTimer += Time.deltaTime;
            if (attackTimer >= timeBetweenAttacks)
            {
                var instantiatedBullet    = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation);
                var updatedTargetPosition = Target.position;
                updatedTargetPosition.y += 1.5f;
                instantiatedBullet.GetComponent <Rigidbody>().velocity = (updatedTargetPosition - bulletEmitter.transform.position).normalized * 20 + CalculateSpread(transform);
                var bulletScript = instantiatedBullet.GetComponent <Bullet>();
                // 20% chance of shooting a bigger and more powerful bullet
                int attackType = Random.Range(0, 5);

                if (attackType == 0)
                {
                    instantiatedBullet.transform.localScale *= 4;
                    bulletScript.Damage = damage * 2;
                }
                else
                {
                    instantiatedBullet.transform.localScale *= 2;
                    bulletScript.Damage = damage;
                }
                bulletScript.IsFriendly = false;
                attackTimer             = 0.0f;
                EnemyAudioSource.clip   = ShootingNoise;
                EnemyAudioSource.Play();
            }
            yield return(null);
        }
    }
Esempio n. 3
0
 public override void PlayAwareNoise()
 {
     EnemyAudioSource.clip = awareNoise;
     EnemyAudioSource.Play();
 }