void DoFire() { if (currentCooldown == 0) { firing = true; if (reloading && data.reloadInterruptSupported && !overheat) { CancelReload(); } else if (!reloading) { if (bulletPool != null) { for (int c = 0; c < data.bulletsPerShot; ++c) { Bullet b = bulletPool.Take().GetComponent <Bullet>(); if (b) { b.tag = owner.tag; Transform nossle = nozzles[currentNossle]; b.transform.position = nossle.position; b.transform.rotation = nossle.rotation; b.transform.RotateAround(nossle.position, Vector3.up, Random.Range(-data.spread / 2, data.spread / 2)); b.rb.velocity = b.transform.forward * b.data.velocity; b.ResetParticle(); b.gameObject.SetActive(true); currentNossle = (currentNossle + 1) % nozzles.Length; OnShotTick?.Invoke(); } else { Debug.LogWarning("no bullet"); } } } load -= data.cost; currentCooldown = data.cooldown; if (load < data.cost) { OnEmpty?.Invoke(); overheat = true; Reload(); } } } }
/// <summary> /// Set the new equiped weapon /// </summary> /// <param name="weapon">New equiped weapon</param> public void SetWeapon(Weapon weapon) { this.equipedWeapon = weapon; this.timeUntilAttacking = weapon.timeBetweenAttack; OnWeaponChanged?.Invoke(weapon); }
IEnumerator DoReload() { if (!reloading) { OnReloadStart?.Invoke(); OnEmpty?.Invoke(); reloading = true; while (load < data.capacity && reloading) { OnReloadTick?.Invoke(); if (reloading) { load++; yield return(new WaitForSeconds(data.loadTime)); } } reloading = false; overheat = false; OnReloadEnd?.Invoke(); } }
public virtual void Unequiped() { OnUnequiped.Invoke(this); }
public virtual void Equiped() { OnEquiped.Invoke(this); }
void CancelReload() { OnReloadCancel?.Invoke(); StopCoroutine(DoReload()); reloading = false; }
public virtual void Unequiped() { OnUnequiped.Invoke(this); Owner = null; Debug.Log(name + Owner); }
public virtual void Equiped() { Debug.Log(name + Owner); OnEquiped.Invoke(this); }