/// <summary>
    /// Shoots bullets with identical time between each bullet
    /// </summary>
    /// <param name="instance"></param>
    /// <param name="shooter"></param>
    /// <param name="direction"></param>
    /// <returns></returns>
    private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter)
    {
        for (int i = 0; i < ClusterCount; i++)
        {
            foreach (Projectile projectile in AmmunitionList)
            {
                //Decide the origin of each bullet
                Vector2 position = ForceLinear ? fireingPoint : shooter.GetProjectilesSpawnPoint();

                Projectile newAmmo = Instantiate(
                    original: projectile,
                    position: position,
                    rotation: Quaternion.identity
                    );

                newAmmo.Direction = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection();

                WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>();
                hurtbox.Shooter = shooter;
                hurtbox.Weapon  = instance;
            }

            //Waiting for next bullet
            yield return(new WaitForSeconds(WaitTime));
        }
    }
Example #2
0
 protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction)
 {
     fireingPointOrigin     = shooter.gameObject.transform.position;
     horizontalDirection    = shooter.gameObject.GetComponent <Flippable>().Direction;
     fireingDirectionOrigin = shooter.GetCurrentAimingDirection();
     shooter.StartCoroutine(CoShootBullets(instance, shooter));
 }
Example #3
0
    /// <summary>
    /// Shoots bullets with identical time between each bullet
    /// </summary>
    /// <param name="instance"></param>
    /// <param name="shooter"></param>
    /// <param name="direction"></param>
    /// <returns></returns>
    private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter)
    {
        for (int i = 0; i < ClusterCount; i++)
        {
            //Decide the origin of each bullet
            Vector2 position = ForceLinear ? fireingPointOrigin : shooter.GetProjectilesSpawnPoint();

            Projectile newAmmo = Instantiate(
                original: Ammunition,
                position: position,
                rotation: Quaternion.identity
                );


            Vector2 Aim = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection();


            // Decides how much each bullet should ne rotated
            if (Aim == Vector2.left)
            {
                newAmmo.transform.Rotate(((90f / ((float)ClusterCount - 1)) * i));
            }
            else if (Aim == Vector2.right)
            {
                newAmmo.transform.Rotate(((90f / ((float)ClusterCount - 1)) * i) * -1);
            }
            else if (Aim == Vector2.up)
            {
                if (horizontalDirection == Direction1D.Left)
                {
                    newAmmo.transform.Rotate(((180f / ((float)ClusterCount - 1)) * i) * -1 + 90);
                }
                else
                {
                    newAmmo.transform.Rotate(((-180f / ((float)ClusterCount - 1)) * i) * -1 - 90);
                }
            }
            else if (Aim == Vector2.down)
            {
                if (horizontalDirection == Direction1D.Left)
                {
                    newAmmo.transform.Rotate(((-180f / ((float)ClusterCount - 1)) * i) * -1 + 90);
                }
                else
                {
                    newAmmo.transform.Rotate(((180f / ((float)ClusterCount - 1)) * i) * -1 - 90);
                }
            }

            WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>();
            hurtbox.Shooter = shooter;
            hurtbox.Weapon  = instance;

            //Waiting for next bullet
            yield return(new WaitForSeconds(WaitTime));
        }
    }
Example #4
0
    /// <summary>
    /// Fires the weapon from the provided weapon shooter
    /// </summary>
    public void Fire(WeaponInstance instance, WeaponShooterBase shooter)
    {
        OnFire(instance, shooter, shooter.GetCurrentAimingDirection());

        if (!Cheats.InfiniteAmmo)
        {
            instance.Durability--;
        }

        instance.LastFireTime = DateTime.Now;
    }
Example #5
0
    /// <summary>
    /// Shoots bullets with identical time between each bullet
    /// </summary>
    /// <param name="instance"></param>
    /// <param name="shooter"></param>
    /// <param name="direction"></param>
    /// <returns></returns>
    private IEnumerator CoShootBullets(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction)
    {
        for (int a = 0; a < NumberOfShots; a++)
        {
            for (int i = 0; i < BulletsPerShot; i++)
            {
                foreach (Projectile projectile in AmmunitionList)
                {
                    Vector2 position = ForceLinear ? fireingPoint : shooter.GetProjectilesSpawnPoint();

                    Vector3 newAmmoPosition;
                    if (direction == Vector2.right || direction == Vector2.left)
                    {
                        newAmmoPosition = new Vector3
                                              (position.x,
                                              position.y + Height / BulletsPerShot * i);
                    }
                    else
                    {
                        newAmmoPosition = new Vector3
                                              (position.x + (Height / BulletsPerShot * i - Height / 2),
                                              position.y);
                    }

                    Projectile newAmmo = Instantiate(
                        original: projectile,
                        position: newAmmoPosition,
                        rotation: Quaternion.identity
                        );

                    newAmmo.Direction = direction;

                    WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>();
                    hurtbox.Shooter = shooter;
                    hurtbox.Weapon  = instance;

                    newAmmo.Direction = ForceLinear ? fireingDirectionOrigin : shooter.GetCurrentAimingDirection();
                }
            }

            //Waiting for next bullet
            yield return(new WaitForSeconds(WaitTime));
        }
    }