Exemple #1
0
        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();
                    }
                }
            }
        }
Exemple #2
0
    /// <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);
    }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
 public virtual void Unequiped()
 {
     OnUnequiped.Invoke(this);
 }
Exemple #5
0
 public virtual void Equiped()
 {
     OnEquiped.Invoke(this);
 }
Exemple #6
0
 void CancelReload()
 {
     OnReloadCancel?.Invoke();
     StopCoroutine(DoReload());
     reloading = false;
 }
Exemple #7
0
 public virtual void Unequiped()
 {
     OnUnequiped.Invoke(this);
     Owner = null;
     Debug.Log(name + Owner);
 }
Exemple #8
0
 public virtual void Equiped()
 {
     Debug.Log(name + Owner);
     OnEquiped.Invoke(this);
 }