/// <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)); } }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int i = 0; i < BlastCount; i++) { Vector3 newAmmoPosition; if (direction == Vector2.right || direction == Vector2.left) { newAmmoPosition = new Vector3 (shooter.GetProjectilesSpawnPoint().x, shooter.GetProjectilesSpawnPoint().y + Height / BlastCount * i); } else { newAmmoPosition = new Vector3 (shooter.GetProjectilesSpawnPoint().x + (Height / BlastCount * i - Height / 2), shooter.GetProjectilesSpawnPoint().y); } Projectile newAmmo = Instantiate( original: Ammunition, position: newAmmoPosition, rotation: Quaternion.identity ); newAmmo.Direction = direction; WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } }
/// <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)); } }
protected override void Start() { base.Start(); _rigidbody = GetComponent <Rigidbody2D>(); _weaponFireHurtBox = GetComponentInChildren <WeaponFireHurtbox>(); //Create a weaponInstance for splittingprojectile SplittingProjectileWeaponInstance = GetComponentInChildren <WeaponFireHurtbox>().Weapon.Template.CreateWeaponInstance(); SplittingProjectileWeaponInstance.Range = SplittingProjectileRange; SplittingProjectileWeaponInstance.BaseDamage = SplittingProjectileDamage; }
protected virtual void Start() { transform.localScale = new Vector3( x: Commons.GetEffectValue(transform.localScale.x, EffectValueType.ProjectileSize), y: Commons.GetEffectValue(transform.localScale.y, EffectValueType.ProjectileSize), z: Commons.GetEffectValue(transform.localScale.z, EffectValueType.ProjectileSize) ); _hurtBox = GetComponentInChildren <WeaponFireHurtbox>(); _weaponInstance = _hurtBox.Weapon; _projectileSpwanPoint = transform.position; //Old code for _projectileSpawnPoint beneath // _projectileSpwanPoint = hurtBox.Shooter.GetProjectilesSpawnPoint(); }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int i = 0; i < BlastCount; i++) { Projectile newAmmo = Instantiate( original: Ammunition, position: shooter.GetProjectilesSpawnPoint(), rotation: Quaternion.identity ); newAmmo.Direction = direction; newAmmo.transform.Rotate((i - BlastCount / 2) * MaxAngle); WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } }
/// <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)); } }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { for (int i = 0; i < BlastCount; i++) { Projectile newAmmo = Instantiate( original: Ammunition, position: shooter.GetProjectilesSpawnPoint(), rotation: Quaternion.identity ); //Rotates the bullet random amount RandomValueBetween randomAngle = new RandomValueBetween(-MaxAngle / 2, MaxAngle / 2); int angle = randomAngle.PickInt(); newAmmo.Direction = direction; newAmmo.transform.Rotate(angle); WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; } }
//Spawn a bunch of projectiles private void Split() { for (int i = 0; i < BlastCount; i++) { //create bullet Projectile newAmmo = Instantiate( original: SplitterProjectile, position: transform.position, rotation: Quaternion.identity ); //rotate bullet newAmmo.Direction = transform.up; newAmmo.transform.Rotate(i * (360f / BlastCount)); //add hurtbox WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = _weaponFireHurtBox.Shooter; hurtbox.Weapon = SplittingProjectileWeaponInstance; } }
protected override void OnFire(WeaponInstance instance, WeaponShooterBase shooter, Vector2 direction) { float rotation = Ammunition.name.Equals("InstantHurtbox") ? UnityEngine.Random.Range(0f, 360f) : 0f; Projectile newAmmo = Instantiate( original: Ammunition, position: shooter.GetProjectilesSpawnPoint() + (direction * Distance), rotation: Quaternion.Euler(0f, 0f, rotation) ); if (rotation == 0) { newAmmo.Direction = direction; } WeaponFireHurtbox hurtbox = newAmmo.GetComponentInChildren <WeaponFireHurtbox>(); hurtbox.Shooter = shooter; hurtbox.Weapon = instance; newAmmo.transform.eulerAngles = newAmmo.transform.eulerAngles.SetY(0); }