public virtual void Fire(Vector3 direction) { Invoke(nameof(End), Life); transform.LookAt(transform.position + direction); Velocity = Speed * direction; OnFired?.Invoke(this, direction); }
public void TryFire(bool alt) { if (Trigger == null || Trigger.AllowFire()) { if ((AmmoAmount > 0 || AmmoAmount == -1) && Holder != null) { if (lastFireTime.HasValue && Time.CurrentTime.Now - lastFireTime < MinTimeBetweenShots) { return; } lastFireTime = Time.CurrentTime.Now; OnFire.Fire(this); OnFired.Fire(); FireInternal(alt); if (AmmoAmount > 0) { AmmoAmount--; if (AmmoAmount == 0) { var alternative = Holder.Inventory.Items .WhereAs <Weapon>() .Where(w => w.Style == this.Style && w.AmmoAmount > 0) .OrderByDescending(w => w.PowerRanking) .FirstOrDefault(); if (alternative != null) { if (alternative.Style == WeaponStyle.Primary) { Holder.Inventory.PrimaryWeapon = alternative; } else { Holder.Inventory.ExplosiveWeapon = alternative; } } } } } else { OnFireEmpty.Fire(this); } } }
void triggerFire() { var force = -controller.target.dir.normalized * bulletVelocity; var nObj = GameObject.Instantiate(bullet); if (fireStart == null) { nObj.transform.position = this.transform.position; nObj.transform.rotation = this.transform.rotation; } else { nObj.transform.position = fireStart.transform.position; nObj.transform.rotation = fireStart.transform.rotation; } nObj.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse); audioSource.PlayOneShot(fireSound); OnFired?.Invoke(this, new EventArgs()); }
public void EventFired() { OnFired?.Invoke(); }