/**
     * @pre: CalculateStats function should be called on a fully built gun first .
     * @post: A shot should be produced if ammo can be deducted successfully and it is not cooling down from prior shot, nothing otherwise.
     * @param: None.
     * @return: Did at least one shot get produced.
     */
    public override bool Fire(Vector3 positon, Quaternion angle)
    {
        if (fireDelay == 0)
        {
            fireDamage = (int)damage / shotsPerSet;
            for (int i = 0; setsPerFire > i; i++)
            {
                for (int j = 0; shotsPerSet > j; j++)
                {
                    if (loadedAmmoCount > 0)
                    {
                        ammo.Fire(new Vector3(0, 0, velocity), positon, angle, precision, fireDamage);
                        fireDelay = baseFireDelay;
                    }
                }
                loadedAmmoCount--;
            }

            return(true);
        }

        else
        {
            return(false);
        }
    }
Exemple #2
0
 void FireProjectile()
 {
     if (Input.GetKey(keyBindings.fire1) && Time.time >= nextFire)
     {
         activeAmmo.Fire(projectileSpawner, transform.rotation);
         nextFire = Time.time + activeAmmo.fireRate;
     }
 }
Exemple #3
0
    public override void Attack(GameObject target, Enemy attacker)
    {
        float distance = Vector2.Distance(attacker.transform.position, target.transform.position);

        if (Time.time >= attacker.nextAttack && distance <= maxRange)
        {
            Vector3 offset      = (target.transform.position - attacker.transform.position);
            float   zRotation   = Mathf.Atan2(offset.y, offset.x) * Mathf.Rad2Deg;
            Vector3 newRotation = new Vector3(0f, 0f, zRotation);
            ammoType.Fire(attacker.gameObject, Quaternion.Euler(newRotation));
            attacker.nextAttack = Time.time + attackRate;
        }
    }