public override void Use()
    {
        if (CanUse() && ammo.SpendAmmo())
        {
            base.Use();
            MuzzleFlash();

            Vector3   dir;
            Transform hit;

            for (int i = 0; i < projectileCount; i++)
            {
                dir = rayShooter.GetRandomDirection(fireFrom, accuracyVariance);
                dir = _angle * dir;
                hit = rayShooter.ShootRay(fireFrom.position, dir);
                Shoot(fireFrom, dir);
                if (dealDamage && hit != null)
                {
                    var damageable = hit.GetComponent <IDamageable>();
                    if (damageable != null)
                    {
                        int damage = damageCalculator.CalculateRandomDamage();
                        damageable.TakeDamage(damage);
                    }
                    forceApplier.ApplyForce(hit, dir);
                }
            }
            EventManager.RaiseOnPlayerNoiseMade(noiseLevel);
        }
    }
Exemple #2
0
    private void Explode(GameObject gameObj)
    {
        if (gameObj == transform.gameObject)
        {
            EventManager.OnObjectAboutToBeDestroyed -= Explode;

            Vector3    explosionPos = transform.position;
            Collider[] colliders    = Physics.OverlapSphere(explosionPos, radius);
            foreach (Collider hit in colliders)
            {
                if (hit != null && hit.GetComponent <Projectile>() == null)
                {
                    Transform trans      = hit.transform;
                    var       damageable = hit.GetComponent <IDamageable>();
                    if (damageable != null)
                    {
                        int damage = damageCalculator.CalculateRandomDamage();
                        damageable.TakeDamage(damage);
                    }
                    StartCoroutine(_AddExplosionForce(trans, force, explosionPos, radius, lift));
                }
            }

            if (explosionPrefab != null)
            {
                var explosionObj = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
                var explosion    = explosionPrefab.GetComponent <ParticleSystem>();
                if (explosion != null)
                {
                    explosion.Play();
                }
                Destroy(explosionObj, duration);
            }
        }
    }
Exemple #3
0
    public override void Use()
    {
        if (CanUse())
        {
            base.Use();
            Vector3   dir;
            Transform hit;

            dir = rayShooter.GetRandomDirection(fireFrom, accuracyVariance);
            hit = rayShooter.ShootRay(fireFrom.position, dir);
            if (hit != null)
            {
                var damageable = hit.GetComponent <IDamageable>();
                if (damageable != null)
                {
                    int damage = damageCalculator.CalculateRandomDamage();
                    damageable.TakeDamage(damage);
                }
                forceApplier.ApplyForce(hit, dir);
            }
        }
    }