Weird Reloading Bugs!!!

Updated on July 5, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on July 5, 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:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  
  
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:

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
  
  
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:

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  
  
  
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;
     }
}

 

And could you maybe look at my other problem? 🙂 

Can’t get data in Multiplayer FPS!!!

 

Please help me! Thanks already in advance!

  • Liked by
  • FaZeBook
Reply