Weird reloading bugs!!!

Updated on June 18, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on June 18, 2018

I have a problem with the Reloading part of the series! I’ve copied Brackeys scripts and I don’t get any Errors, but I have still weird functionalities on this Behaviour! When I make rapid fire, everything works! BUT when I click the Fire Button just once, unhand the fire button and then another time click once, its reloading, although the weapon has 29 Bullets! Also when I make rapid fire, but not until I have 0 bullets, but maybe 15 and I unhand the fire button. Then I click the fire Button again, my weapon is reloading, although I have 15 bullets! So I can’t make Single Fire in a row!!! Please look at my code and help me!!!

 

Here are the important parts to reload of my PlayerShoot, WeaponManager and PlayerWeapon scripts:

 

 

 

PlayerShoot:

 

 

 

 
 
 
void Update()
 {
 
 
 
    if (currentWeapon.bullets < currentWeapon.maxBullets)
     {
         if (Input.GetButtonDown("Reload"))
         {
         weaponManager.Reload();
         return;
         }
     }
 
 
 
}
 
 
 
 
 
 
 
[Client]
 void Shoot()
 {
     if (!isLocalPlayer || weaponManager.isReloading)
     {
         return;
     }
 
 
 
    if (currentWeapon.bullets <= 0)
     {
         weaponManager.Reload();
         return;
     }
 
 
 
    currentWeapon.bullets--;
 
 
 

 

 

 

WeaponManger:

 

 

 

 
 
 
public void Reload()
 {
     if (isReloading)
         return;
 
 
 
    StartCoroutine(Reload_Coroutine());
 }
 
 
 
private IEnumerator Reload_Coroutine()
 {
 
 
 
    isReloading = true;
 
 
 
    CmdOnReload();
 
 
 
    yield return new WaitForSeconds(currentWeapon.reloadTime);
 
 
 
    currentWeapon.bullets = currentWeapon.maxBullets;
 
 
 
    isReloading = false;
 }
 
 
 
[Command]
 void CmdOnReload()
 {
     RpcOnReload();
 }
 
 
 
[ClientRpc]
 void RpcOnReload()
 {
     Animator anim = currentGFX.GetComponent();
     if (anim != null)
     {
         anim.SetTrigger("Reload");
     }
 }

 

 

 

PlayerWeapon:

 

 

 

 
 
 
using UnityEngine;
 
 
 
[System.Serializable]
public class PlayerWeapon {
 
 
 
    public string name = "M4";
 
 
 
    public int damage = 10;
     public float range = 100f;
 
 
 
    public float fireRate = 0f;
 
 
 
    public int maxBullets = 30;
     [HideInInspector]
     public int bullets = 30;
 
 
 
    public float reloadTime = 1.2f;
 
 
 
    public GameObject GFX;
 
 
 
    public PlayerWeapon ()
     {
     WeaponBullets();
     }
 
 
 
    private void WeaponBullets()
     {
         bullets = maxBullets;
     }
}

 

 

 

Please help me! Thanks already in advance!

  • Liked by
  • FaZeBook
Reply