Example #1
0
    private void FireProjectile()
    {
        GameObject bullet = ObjectPoolManager.Spawn(projectilePrefab, firePoint.position, firePoint.rotation);
        IShootable shot   = bullet.GetComponent <IShootable>();

        IAudio player = ObjectPoolManager.Spawn(audioPlayerPrefab.gameObject, transform.position, transform.rotation).GetComponent <IAudio>();

        player.SetUpAudioSource(AudioManager.instance.GetSound("SlimeFireProjectile"));
        player.PlayAtRandomPitch();
        float dmg   = Random.Range(settings.minDamage, settings.maxDamage);
        float kBack = Random.Range(settings.minKnockBack, settings.minKnockBack);

        shot.SetUpBullet(kBack, dmg);
        shot.Shoot(firePoint.up, shootForce);
        canAttack = false;
        Invoke("ResetShotTime", Random.Range(Mathf.Clamp(settings.attackRate - 1.5f, 0f, settings.attackRate), settings.attackRate + 1.5f));
    }
Example #2
0
    public void SpawnFragments()
    {
        float      angleIncrement = 360f / fragmentCounts;
        float      currentAngle   = 0f;
        GameObject currentFragment;

        for (int i = 0; i < fragmentCounts; i++)
        {
            int rand = Random.Range(0, slimeFragmentsPrefabs.Count);
            currentFragment = ObjectPoolManager.Spawn(slimeFragmentsPrefabs[rand], transform.position);

            Vector3 dir = EssoUtility.GetVectorFromAngle(currentAngle).normalized;
            currentFragment.transform.up = dir;
            IShootable frag = currentFragment.GetComponent <IShootable>();
            frag.SetUpBullet(knockBack / fragmentCounts, damage / fragmentCounts);
            frag.Shoot(dir, shotForce * 0.8f);
            currentAngle += angleIncrement;
        }
    }
Example #3
0
    virtual public void Shoot()
    {
        //Shoot behaviour
        //If ammo is available and can shoot
        if (currentClip > 0 && canShoot)
        {
            CamShake.instance.DoScreenShake(time, magnitude, smoothIn, smoothOut);
            //Instatiate a bullet
            GameObject  bullet   = ObjectPoolManager.Spawn(bulletPrefab, firePoint.position, firePoint.rotation);
            IShootable  shot     = bullet.GetComponent <IShootable>();
            Rigidbody2D bulletRB = bullet.GetComponent <Rigidbody2D>();//Get RB component


            if (bulletRB != null)
            {
                BeginMuzzleVFX();
                AudioManager.instance.PlayAtRandomPitch(shootSFX);
                //Adds force to shoot bullet
                float dmg = Random.Range(minDamage, maxDamage);
                bulletRB.AddForce(firePoint.up * shotForce, ForceMode2D.Impulse);
                shot.SetUpBullet(knockBack, dmg);
                currentClip--;
                canShoot = false;
            }
            else
            {
                //bullet can't get shot so just destroy
                ObjectPoolManager.Recycle(bulletRB);
            }
            StartCoroutine(ShotDelay());
        }
        else if (currentClip <= 0)
        {
            AudioManager.instance.PlayAtRandomPitch("OutOfAmmoSFX");
        }
    }