Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Client is not recieving the float like the host does

Discussion in 'Connected Games' started by Vexer, Jun 11, 2018.

  1. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    Hey guys for some reason my host can shoot every 15 bullets then he reloads and gets 15 bullets back but for some reason my client doesn't get bullets back and my client can also not press "R" to reload for some reason this is my script please let me know what iam doing wrong :(

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6.  
    7. public class Gun : NetworkBehaviour {
    8.     public Camera fpsCam;
    9.     public ParticleSystem muzzleFlash;
    10.     public ParticleSystem Tracer;
    11.  
    12.     public float damage = 10f;
    13.     public float range = 100f;
    14.     public float fireRate = 3.5f;
    15.     public float Bullets = 15;
    16.     private float BulletCount;
    17.     private float MaxBulletCount;
    18.  
    19.     public Text bulletCount;
    20.     public Text maxBulletCount;
    21.  
    22.     public bool BeforeAiming;
    23.     public bool isAiming;
    24.     public bool AfterAiming;
    25.  
    26.     public Animator anim;
    27.  
    28.     private float nextTimeToFire = 0f;
    29.  
    30.     public AudioClip shoot;
    31.     public AudioClip hitsound;
    32.     public AudioClip reload;
    33.  
    34.     public GameObject MuzzleFlash;
    35.  
    36.     private AudioSource audioSource;
    37.     public AudioSource audioSource2;
    38.     float speed = 0.2f;
    39.     public GameObject crosshair;
    40.     public GameObject hitmarker;
    41.  
    42.     public int minDmgHead = 45;
    43.     public int maxDmgHead = 70;
    44.     public int minDmgTorso = 15;
    45.     public int maxDmgTorso = 25;
    46.     public int minDmgLeg = 5;
    47.     public int maxDmgLeg = 10;
    48.  
    49.     void Start()
    50.     {
    51.         audioSource = GetComponent<AudioSource>();
    52.         hitmarker.SetActive(false);
    53.         if (!isLocalPlayer)
    54.             return;
    55.         crosshair.SetActive(true);
    56.             BulletCount = 15f;
    57.         MaxBulletCount = 75f;
    58.         SetBulletCount();
    59.         SetMaxBulletCount();
    60.     }
    61.  
    62.     // Update is called once per frame
    63.     void Update() {
    64.         if (!isLocalPlayer) return;
    65.  
    66.         if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire) {
    67.  
    68.             nextTimeToFire = Time.time + 1f / fireRate;
    69.             audioSource.clip = shoot;
    70.             audioSource.Play();
    71.             CmdShoot();
    72.             CmdMuzzleFlash();
    73.             muzzleFlash.Play();
    74.         }
    75.  
    76.         if (Input.GetMouseButton(1))
    77.         {
    78.             StartCoroutine(Aiming());
    79.         }
    80.  
    81.         if (!Input.GetMouseButton(1))
    82.         {
    83.             StartCoroutine(afterAiming());
    84.             isAiming = false;
    85.             anim.SetBool("isAiming", false);
    86.         }
    87.  
    88.         if (Input.GetMouseButtonUp(1))
    89.         {
    90.             AfterAiming = true;
    91.             anim.SetBool("AfterAiming", AfterAiming);
    92.             anim.SetBool("AfterAiming", true);
    93.             StartCoroutine(afterAiming());
    94.         }
    95.  
    96.         if (Input.GetMouseButtonDown(1))
    97.         {
    98.             BeforeAiming = true;
    99.             anim.SetBool("BeforeAiming", BeforeAiming);
    100.             anim.SetBool("BeforeAiming", true);
    101.         }
    102.  
    103.         if (Input.GetKeyDown(KeyCode.R) && Bullets <= 14f)
    104.         {
    105.             if (isLocalPlayer)
    106.             {
    107.                 anim.SetTrigger("isReloading");
    108.                 StartCoroutine(NoAmmo());
    109.             }
    110.             CmdReload();
    111.         }
    112.     }
    113.  
    114.     void SetBulletCount()
    115.     {
    116.         if (BulletCount < 0)
    117.         {
    118.             BulletCount = 0;
    119.         }
    120.  
    121.         if (MaxBulletCount < 0)
    122.         {
    123.             MaxBulletCount = 0;
    124.         }
    125.         bulletCount.text = BulletCount.ToString();
    126.         maxBulletCount.text = MaxBulletCount.ToString();
    127.     }
    128.  
    129.     void SetMaxBulletCount()
    130.     {
    131.         if (MaxBulletCount < 0)
    132.         {
    133.             MaxBulletCount = 0;
    134.         }
    135.         maxBulletCount.text = MaxBulletCount.ToString();
    136.     }
    137.     IEnumerator Aiming()
    138.     {
    139.         //Wait for 0.5 seconds
    140.         yield return new WaitForSeconds(0.25f);
    141.         BeforeAiming = false;
    142.         anim.SetBool("BeforeAiming", false);
    143.  
    144.         isAiming = true;
    145.         anim.SetBool("isAiming", isAiming);
    146.         anim.SetBool("isAiming", true);
    147.  
    148.     }
    149.  
    150.     IEnumerator afterAiming()
    151.     {
    152.         //Wait for 0.5 seconds
    153.         yield return new WaitForSeconds(0.25f);
    154.         AfterAiming = false;
    155.         anim.SetBool("AfterAiming", AfterAiming);
    156.         anim.SetBool("AfterAiming", false);
    157.  
    158.     }
    159.  
    160.     IEnumerator NoAmmo()
    161.     {
    162.         if (isLocalPlayer)
    163.         {
    164.             isAiming = false;
    165.             anim.SetBool("isAiming", isAiming);
    166.             anim.SetBool("isAiming", false);
    167.             audioSource2.clip = reload;
    168.             audioSource2.Play();
    169.             range = 0f;
    170.             MuzzleFlash.SetActive(false);
    171.             audioSource.enabled = false;
    172.  
    173.             //Wait for 2 seconds
    174.             yield return new WaitForSeconds(2f);
    175.  
    176.             Bullets = 15f;
    177.             BulletCount = 15f;
    178.             MaxBulletCount -= 15f;
    179.             SetMaxBulletCount();
    180.             SetBulletCount();
    181.             range = 100f;
    182.             MuzzleFlash.SetActive(true);
    183.             audioSource.enabled = true;
    184.             if (isAiming)
    185.             {
    186.                 BeforeAiming = true;
    187.                 anim.SetBool("BeforeAiming", true);
    188.             }
    189.  
    190.         }
    191.     }
    192.  
    193.     IEnumerator waiter()
    194.     {
    195.         hitmarker.SetActive(true);
    196.         crosshair.SetActive(false);
    197.  
    198.         //Wait for 4 seconds
    199.         yield return new WaitForSeconds(0.2f);
    200.  
    201.         hitmarker.SetActive(false);
    202.         crosshair.SetActive(true);
    203.  
    204.     }
    205.  
    206.     [Command]
    207.     void CmdReload()
    208.     {
    209.         RpcReload();
    210.     }
    211.  
    212.     [ClientRpc]
    213.     void RpcReload()
    214.     {
    215.         if (!isLocalPlayer)
    216.             return;
    217.         anim.SetTrigger("isReloading");
    218.         StartCoroutine(NoAmmo());
    219.     }
    220.  
    221.     [Command]
    222.     void CmdMuzzleFlash()
    223.     {
    224.         RpcMuzzleFlash();
    225.     }
    226.  
    227.     [ClientRpc]
    228.     void RpcMuzzleFlash()
    229.     {
    230.         if (isLocalPlayer)
    231.             return;
    232.         muzzleFlash.Play();
    233.     }
    234.  
    235.     [Command]
    236.     void CmdShootSound()
    237.     {
    238.         RpcShootSound();
    239.     }
    240.  
    241.     [ClientRpc]
    242.     void RpcShootSound()
    243.     {
    244.         if (isLocalPlayer)
    245.             return;
    246.         audioSource.clip = shoot;
    247.         audioSource.Play();
    248.     }
    249.  
    250.     [Command]
    251.     void CmdHitSound()
    252.     {
    253.         RpcHitSound();
    254.     }
    255.  
    256.     [ClientRpc]
    257.     void RpcHitSound()
    258.     {
    259.         if (!isLocalPlayer)
    260.             return;
    261.         audioSource2.clip = hitsound;
    262.         audioSource2.Play();
    263.     }
    264.  
    265.     [Command]
    266.     void CmdHitMarker()
    267.     {
    268.         RpcHitMarker();
    269.     }
    270.  
    271.     [ClientRpc]
    272.     void RpcHitMarker()
    273.     {
    274.         if (!isLocalPlayer)
    275.             return;
    276.         StartCoroutine(waiter());
    277.  
    278.     }
    279.  
    280.     [Command]
    281.     void CmdShoot()
    282.     {
    283.         Bullets -= 1f;
    284.         BulletCount = BulletCount -1f;
    285.         SetBulletCount();
    286.  
    287.         if (Bullets == 0)
    288.             {
    289.                 anim.SetTrigger("isReloading");
    290.                 StartCoroutine(NoAmmo());
    291.             CmdReload();
    292.             }
    293.  
    294.             if (Bullets < 0)
    295.             {
    296.                 Bullets = 0f;
    297.             }
    298.         RaycastHit hit;
    299.         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    300.         {
    301.  
    302.             Debug.Log(hit.transform.name);
    303.  
    304.             Health health = hit.transform.GetComponent<Health>();
    305.  
    306.  
    307.             if (health != null)
    308.             {
    309.                 CmdHitSound();
    310.                 CmdHitMarker();
    311.  
    312.                 if (hit.collider.tag == "Head")
    313.                 {
    314.                     health.CmdTakeDamage(Random.Range(minDmgHead, maxDmgHead));
    315.                 }
    316.  
    317.                 else if (hit.collider.tag == "Torso")
    318.                 {
    319.                     health.CmdTakeDamage(Random.Range(minDmgTorso, maxDmgTorso));
    320.                 }
    321.  
    322.                 else if (hit.collider.tag == "Leg")
    323.                 {
    324.                     health.CmdTakeDamage(Random.Range(minDmgLeg, maxDmgLeg));
    325.                 }
    326.             }
    327.         }
    328.     }
    329. }
    330.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,041
    For a client, whenever they fire and the server's version of Bullets == 0, it will try to run the NoAmmo coroutine on the server. This won't do anything because the first thing you do is check for isLocalPlayer, which will always be false on the server for the client's player object. Also not sure why you're running CmdReload() from CmdShoot(), since within a command you already know you're the server so no need to run as a command. You should just run RpcReload().

    You're also using the client version of Bullets to check if you should allow the R button to reload, but you're never subtracting from it on the client. You're subtracting from Bullets whenenver you fire on the server only, and you're not doing anything to sync up these two separate variables.

    It looks like you're having difficulty differentiating what is running on the client from what is running on the server, and what values each has for their separate copies of all these variables you're using.
     
  3. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    Thx for your response so i should start with changing: public float Bullets = 15; to [SyncVar] public float Bullets = 15; ??is that a good way to sync it?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,041
    If you did that, you would have to stop modifying Bullets (or any syncvar) on the client, and only do it on the server.

    Also, if you're not dealing with values smaller than 1, you should use int instead of float. Unless there are times the player will fire fractions of a bullet. Otherwise you're going to run into instances where float precision results in having 0.9999999 bullets when you expect 1.0 bullets.
     
  5. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    Thank you for your help just one last question could you explain with the code that i have right now why my muzzle flash dissapears on my host like it should if he has 0 bullets but if the client has 0 it still shows the muzzle flash?
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6.  
    7. public class Gun : NetworkBehaviour {
    8.     public Camera fpsCam;
    9.     public ParticleSystem muzzleFlash;
    10.     public ParticleSystem Tracer;
    11.  
    12.     public float damage = 10f;
    13.     public float range = 100f;
    14.     public float fireRate = 3.5f;
    15.    [SyncVar] public int Bullets = 15;
    16.     private int BulletCount;
    17.     private int MaxBulletCount;
    18.  
    19.     public Text bulletCount;
    20.     public Text maxBulletCount;
    21.  
    22.     public bool BeforeAiming;
    23.     public bool isAiming;
    24.     public bool AfterAiming;
    25.  
    26.     public Animator anim;
    27.  
    28.     private float nextTimeToFire = 0f;
    29.  
    30.     public AudioClip shoot;
    31.     public AudioClip hitsound;
    32.     public AudioClip reload;
    33.  
    34.     public GameObject MuzzleFlash;
    35.  
    36.     private AudioSource audioSource;
    37.     public AudioSource audioSource2;
    38.     float speed = 0.2f;
    39.     public GameObject crosshair;
    40.     public GameObject hitmarker;
    41.  
    42.     public int minDmgHead = 45;
    43.     public int maxDmgHead = 70;
    44.     public int minDmgTorso = 15;
    45.     public int maxDmgTorso = 25;
    46.     public int minDmgLeg = 5;
    47.     public int maxDmgLeg = 10;
    48.  
    49.     void Start()
    50.     {
    51.         audioSource = GetComponent<AudioSource>();
    52.         hitmarker.SetActive(false);
    53.         if (!isLocalPlayer)
    54.             return;
    55.         crosshair.SetActive(true);
    56.             BulletCount = 15;
    57.         MaxBulletCount = 75;
    58.         SetBulletCount();
    59.         SetMaxBulletCount();
    60.     }
    61.  
    62.     // Update is called once per frame
    63.     void Update() {
    64.         if (!isLocalPlayer) return;
    65.  
    66.         if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire) {
    67.  
    68.             nextTimeToFire = Time.time + 1f / fireRate;
    69.             audioSource.clip = shoot;
    70.             audioSource.Play();
    71.             CmdShoot();
    72.             CmdMuzzleFlash();
    73.             muzzleFlash.Play();
    74.         }
    75.  
    76.         if (Input.GetMouseButton(1))
    77.         {
    78.             StartCoroutine(Aiming());
    79.         }
    80.  
    81.         if (!Input.GetMouseButton(1))
    82.         {
    83.             StartCoroutine(afterAiming());
    84.             isAiming = false;
    85.             anim.SetBool("isAiming", false);
    86.         }
    87.  
    88.         if (Input.GetMouseButtonUp(1))
    89.         {
    90.             AfterAiming = true;
    91.             anim.SetBool("AfterAiming", AfterAiming);
    92.             anim.SetBool("AfterAiming", true);
    93.             StartCoroutine(afterAiming());
    94.         }
    95.  
    96.         if (Input.GetMouseButtonDown(1))
    97.         {
    98.             BeforeAiming = true;
    99.             anim.SetBool("BeforeAiming", BeforeAiming);
    100.             anim.SetBool("BeforeAiming", true);
    101.         }
    102.  
    103.         if (Input.GetKeyDown(KeyCode.R) && Bullets <= 14 && MaxBulletCount >= 1)
    104.         {
    105.                 anim.SetTrigger("isReloading");
    106.             audioSource2.clip = reload;
    107.             audioSource2.Play();
    108.             StartCoroutine(NoAmmo());
    109.         }
    110.     }
    111.  
    112.     void SetBulletCount()
    113.     {
    114.         if (isLocalPlayer)
    115.         {
    116.             if (BulletCount < 0)
    117.             {
    118.                 BulletCount = 0;
    119.             }
    120.  
    121.             if (MaxBulletCount < 0)
    122.             {
    123.                 MaxBulletCount = 0;
    124.             }
    125.             bulletCount.text = BulletCount.ToString();
    126.             maxBulletCount.text = MaxBulletCount.ToString();
    127.         }
    128.     }
    129.  
    130.     void SetMaxBulletCount()
    131.     {
    132.         if (isLocalPlayer)
    133.         {
    134.             if (MaxBulletCount < 0)
    135.             {
    136.                 MaxBulletCount = 0;
    137.             }
    138.             maxBulletCount.text = MaxBulletCount.ToString();
    139.         }
    140.     }
    141.     IEnumerator Aiming()
    142.     {
    143.         //Wait for 0.5 seconds
    144.         yield return new WaitForSeconds(0.25f);
    145.         BeforeAiming = false;
    146.         anim.SetBool("BeforeAiming", false);
    147.  
    148.         isAiming = true;
    149.         anim.SetBool("isAiming", isAiming);
    150.         anim.SetBool("isAiming", true);
    151.  
    152.     }
    153.  
    154.     IEnumerator afterAiming()
    155.     {
    156.         //Wait for 0.5 seconds
    157.         yield return new WaitForSeconds(0.1f);
    158.         AfterAiming = false;
    159.         anim.SetBool("AfterAiming", AfterAiming);
    160.         anim.SetBool("AfterAiming", false);
    161.  
    162.     }
    163.  
    164.     IEnumerator NoAmmo()
    165.     {
    166.             isAiming = false;
    167.             anim.SetBool("isAiming", isAiming);
    168.             anim.SetBool("isAiming", false);
    169.             range = 0f;
    170.             MuzzleFlash.SetActive(false);
    171.             audioSource.enabled = false;
    172.  
    173.             //Wait for 2 seconds
    174.             yield return new WaitForSeconds(2f);
    175.  
    176.             Bullets = 15;
    177.             BulletCount = 15;
    178.             MaxBulletCount -= 15;
    179.             SetMaxBulletCount();
    180.             SetBulletCount();
    181.             range = 100f;
    182.             MuzzleFlash.SetActive(true);
    183.             audioSource.enabled = true;
    184.             if (isAiming)
    185.             {
    186.                 BeforeAiming = true;
    187.                 anim.SetBool("BeforeAiming", true);
    188.             }
    189.     }
    190.  
    191.     IEnumerator waiter()
    192.     {
    193.         hitmarker.SetActive(true);
    194.         crosshair.SetActive(false);
    195.  
    196.         //Wait for 4 seconds
    197.         yield return new WaitForSeconds(0.2f);
    198.  
    199.         hitmarker.SetActive(false);
    200.         crosshair.SetActive(true);
    201.  
    202.     }
    203.     [Command]
    204.     void CmdReload()
    205.     {
    206.         RpcReload();
    207.     }
    208.  
    209.     [ClientRpc]
    210.     void RpcReload()
    211.     {
    212.         anim.SetTrigger("isReloading");
    213.         StartCoroutine(NoAmmo());
    214.     }
    215.     [Command]
    216.     void CmdMuzzleFlash()
    217.     {
    218.         RpcMuzzleFlash();
    219.     }
    220.  
    221.     [ClientRpc]
    222.     void RpcMuzzleFlash()
    223.     {
    224.         if (isLocalPlayer)
    225.             return;
    226.         muzzleFlash.Play();
    227.     }
    228.  
    229.     [Command]
    230.     void CmdShootSound()
    231.     {
    232.         RpcShootSound();
    233.     }
    234.  
    235.     [ClientRpc]
    236.     void RpcShootSound()
    237.     {
    238.         if (isLocalPlayer)
    239.             return;
    240.         audioSource.clip = shoot;
    241.         audioSource.Play();
    242.     }
    243.  
    244.     [Command]
    245.     void CmdHitSound()
    246.     {
    247.         RpcHitSound();
    248.     }
    249.  
    250.     [ClientRpc]
    251.     void RpcHitSound()
    252.     {
    253.         if (!isLocalPlayer)
    254.             return;
    255.         audioSource2.clip = hitsound;
    256.         audioSource2.Play();
    257.     }
    258.  
    259.     [Command]
    260.     void CmdHitMarker()
    261.     {
    262.         RpcHitMarker();
    263.     }
    264.  
    265.     [ClientRpc]
    266.     void RpcHitMarker()
    267.     {
    268.         if (!isLocalPlayer)
    269.             return;
    270.         StartCoroutine(waiter());
    271.  
    272.     }
    273.  
    274.     [ClientRpc]
    275.     void RpcNoAmmoLeft()
    276.     {
    277.         range = 0;
    278.         MuzzleFlash.SetActive(false);
    279.         audioSource.enabled = false;
    280.     }
    281.  
    282.     [Command]
    283.     void CmdShoot()
    284.     {
    285.         RpcShoot();
    286.  
    287.         Bullets -= 1;
    288.  
    289.         if (Bullets == 0 && MaxBulletCount >= 1)
    290.             {
    291.                 anim.SetTrigger("isReloading");
    292.                 StartCoroutine(NoAmmo());
    293.             audioSource2.clip = reload;
    294.             audioSource2.Play();
    295.             RpcReload();
    296.             }
    297.  
    298.             if (Bullets < 0)
    299.             {
    300.                 Bullets = 0;
    301.             }
    302.  
    303.         if (Bullets == 0 && BulletCount == 0 && MaxBulletCount == 0)
    304.         {
    305.             range = 0;
    306.             MuzzleFlash.SetActive(false);
    307.             audioSource.enabled = false;
    308.             RpcNoAmmoLeft();
    309.         }
    310.         RaycastHit hit;
    311.         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    312.         {
    313.  
    314.             Debug.Log(hit.transform.name);
    315.  
    316.             Health health = hit.transform.GetComponent<Health>();
    317.  
    318.  
    319.             if (health != null)
    320.             {
    321.                 CmdHitSound();
    322.                 CmdHitMarker();
    323.  
    324.                 if (hit.collider.tag == "Head")
    325.                 {
    326.                     health.CmdTakeDamage(Random.Range(minDmgHead, maxDmgHead));
    327.                 }
    328.  
    329.                 else if (hit.collider.tag == "Torso")
    330.                 {
    331.                     health.CmdTakeDamage(Random.Range(minDmgTorso, maxDmgTorso));
    332.                 }
    333.  
    334.                 else if (hit.collider.tag == "Leg")
    335.                 {
    336.                     health.CmdTakeDamage(Random.Range(minDmgLeg, maxDmgLeg));
    337.                 }
    338.             }
    339.         }
    340.     }
    341.  
    342.     [ClientRpc]
    343.     void RpcShoot()
    344.     {
    345.         BulletCount = BulletCount - 1;
    346.         SetBulletCount();
    347.     }
    348. }
    349.  
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,041
    Not sure, but I see you're still calling NoAmmo on the client, which sets the value of Bullets. This will likely get its value out of sync with the server's value until the server's value changes and updates the client (unless the client happens to update the syncvar with the same value it already was set to).
     
  7. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    Yesterday it looked like it fixed my problem but i guess it didn't for some reason my host can only again reload if his bullets are 0 but if the clients bullets are 0 nothing happends:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6.  
    7. public class Gun : NetworkBehaviour {
    8.     public Camera fpsCam;
    9.     public ParticleSystem muzzleFlash;
    10.     public ParticleSystem Tracer;
    11.  
    12.     public float damage = 10f;
    13.     public float range = 100f;
    14.     public float fireRate = 3.5f;
    15.    [SyncVar] public int Bullets = 15;
    16.     private int BulletCount;
    17.     private int MaxBulletCount;
    18.     [SyncVar] public int BulletsShot;
    19.  
    20.     public Text bulletCount;
    21.     public Text maxBulletCount;
    22.  
    23.     public bool BeforeAiming;
    24.     public bool isAiming;
    25.     public bool AfterAiming;
    26.  
    27.     public Animator anim;
    28.  
    29.     private float nextTimeToFire = 0f;
    30.  
    31.     public bool isReloading;
    32.  
    33.     public AudioClip shoot;
    34.     public AudioClip hitsound;
    35.     public AudioClip reload;
    36.  
    37.     public GameObject MuzzleFlash;
    38.  
    39.     private AudioSource audioSource;
    40.     public AudioSource audioSource2;
    41.     float speed = 0.2f;
    42.     public GameObject crosshair;
    43.     public GameObject hitmarker;
    44.  
    45.     public int minDmgHead = 45;
    46.     public int maxDmgHead = 70;
    47.     public int minDmgTorso = 15;
    48.     public int maxDmgTorso = 25;
    49.     public int minDmgLeg = 5;
    50.     public int maxDmgLeg = 10;
    51.  
    52.     void Start()
    53.     {
    54.         audioSource = GetComponent<AudioSource>();
    55.         hitmarker.SetActive(false);
    56.         if (!isLocalPlayer)
    57.             return;
    58.         crosshair.SetActive(true);
    59.         BulletsShot = 0;
    60.             BulletCount = 15;
    61.         MaxBulletCount = 75;
    62.         SetBulletCount();
    63.         SetMaxBulletCount();
    64.     }
    65.  
    66.     // Update is called once per frame
    67.     void Update() {
    68.         if (!isLocalPlayer) return;
    69.  
    70.         if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire && isReloading == false) {
    71.  
    72.             nextTimeToFire = Time.time + 1f / fireRate;
    73.             audioSource.clip = shoot;
    74.             audioSource.Play();
    75.             CmdShoot();
    76.             CmdMuzzleFlash();
    77.             muzzleFlash.Play();
    78.         }
    79.  
    80.         if (Input.GetMouseButton(1))
    81.         {
    82.             StartCoroutine(Aiming());
    83.         }
    84.  
    85.         if (!Input.GetMouseButton(1))
    86.         {
    87.             StartCoroutine(afterAiming());
    88.             isAiming = false;
    89.             anim.SetBool("isAiming", false);
    90.         }
    91.  
    92.         if (Input.GetMouseButtonUp(1))
    93.         {
    94.             AfterAiming = true;
    95.             anim.SetBool("AfterAiming", AfterAiming);
    96.             anim.SetBool("AfterAiming", true);
    97.             StartCoroutine(afterAiming());
    98.         }
    99.  
    100.         if (Input.GetMouseButtonDown(1))
    101.         {
    102.             BeforeAiming = true;
    103.             anim.SetBool("BeforeAiming", BeforeAiming);
    104.             anim.SetBool("BeforeAiming", true);
    105.         }
    106.  
    107.         if (Input.GetKeyDown(KeyCode.R) && Bullets <= 14 && MaxBulletCount >= 1 && isReloading == false)
    108.         {
    109.                 anim.SetTrigger("isReloading");
    110.             audioSource2.clip = reload;
    111.             audioSource2.Play();
    112.             StartCoroutine(NoAmmo());
    113.         }
    114.     }
    115.  
    116.     void SetBulletCount()
    117.     {
    118.         if (isLocalPlayer)
    119.         {
    120.             if (BulletCount < 0)
    121.             {
    122.                 BulletCount = 0;
    123.             }
    124.  
    125.             if (MaxBulletCount < 0)
    126.             {
    127.                 MaxBulletCount = 0;
    128.             }
    129.             bulletCount.text = BulletCount.ToString();
    130.             maxBulletCount.text = MaxBulletCount.ToString();
    131.         }
    132.     }
    133.  
    134.     void SetMaxBulletCount()
    135.     {
    136.         if (isLocalPlayer)
    137.         {
    138.             if (MaxBulletCount < 0)
    139.             {
    140.                 MaxBulletCount = 0;
    141.             }
    142.             maxBulletCount.text = MaxBulletCount.ToString();
    143.         }
    144.     }
    145.     IEnumerator Aiming()
    146.     {
    147.         //Wait for 0.5 seconds
    148.         yield return new WaitForSeconds(0.25f);
    149.         BeforeAiming = false;
    150.         anim.SetBool("BeforeAiming", false);
    151.  
    152.         isAiming = true;
    153.         anim.SetBool("isAiming", isAiming);
    154.         anim.SetBool("isAiming", true);
    155.  
    156.     }
    157.  
    158.     IEnumerator afterAiming()
    159.     {
    160.         //Wait for 0.5 seconds
    161.         yield return new WaitForSeconds(0.1f);
    162.         AfterAiming = false;
    163.         anim.SetBool("AfterAiming", AfterAiming);
    164.         anim.SetBool("AfterAiming", false);
    165.  
    166.     }
    167.  
    168.     IEnumerator NoAmmo()
    169.     {
    170.         isReloading = true;
    171.         CmdIsReloading();
    172.         isAiming = false;
    173.             anim.SetBool("isAiming", isAiming);
    174.             anim.SetBool("isAiming", false);
    175.             range = 0f;
    176.             MuzzleFlash.SetActive(false);
    177.             audioSource.enabled = false;
    178.  
    179.             //Wait for 2 seconds
    180.             yield return new WaitForSeconds(2f);
    181.         isReloading = false;
    182.         CmdIsNotReloading();
    183.             Bullets = 15;
    184.             BulletCount = 15;
    185.         MaxBulletCount -= BulletsShot;
    186.             SetMaxBulletCount();
    187.         BulletsShot = 0;
    188.         CmdSetBulletsShot();
    189.         SetBulletCount();
    190.         range = 100f;
    191.             MuzzleFlash.SetActive(true);
    192.             audioSource.enabled = true;
    193.             if (isAiming)
    194.             {
    195.                 BeforeAiming = true;
    196.                 anim.SetBool("BeforeAiming", true);
    197.             }
    198.     }
    199.  
    200.     IEnumerator waiter()
    201.     {
    202.         hitmarker.SetActive(true);
    203.         crosshair.SetActive(false);
    204.  
    205.         //Wait for 4 seconds
    206.         yield return new WaitForSeconds(0.2f);
    207.  
    208.         hitmarker.SetActive(false);
    209.         crosshair.SetActive(true);
    210.  
    211.     }
    212.     [Command]
    213.     void CmdReload()
    214.     {
    215.         RpcReload();
    216.     }
    217.  
    218.     [ClientRpc]
    219.     void RpcReload()
    220.     {
    221.         anim.SetTrigger("isReloading");
    222.         StartCoroutine(NoAmmo());
    223.     }
    224.  
    225.     [Command]
    226.     void CmdMuzzleFlash()
    227.     {
    228.         RpcMuzzleFlash();
    229.     }
    230.  
    231.     [ClientRpc]
    232.     void RpcMuzzleFlash()
    233.     {
    234.         if (isLocalPlayer)
    235.             return;
    236.         muzzleFlash.Play();
    237.     }
    238.  
    239.     [Command]
    240.     void CmdShootSound()
    241.     {
    242.         RpcShootSound();
    243.     }
    244.  
    245.     [ClientRpc]
    246.     void RpcShootSound()
    247.     {
    248.         if (isLocalPlayer)
    249.             return;
    250.         audioSource.clip = shoot;
    251.         audioSource.Play();
    252.     }
    253.  
    254.     [Command]
    255.     void CmdHitSound()
    256.     {
    257.         RpcHitSound();
    258.     }
    259.  
    260.     [ClientRpc]
    261.     void RpcHitSound()
    262.     {
    263.         if (!isLocalPlayer)
    264.             return;
    265.         audioSource2.clip = hitsound;
    266.         audioSource2.Play();
    267.     }
    268.  
    269.     [Command]
    270.     void CmdHitMarker()
    271.     {
    272.         RpcHitMarker();
    273.     }
    274.  
    275.     [ClientRpc]
    276.     void RpcHitMarker()
    277.     {
    278.         if (!isLocalPlayer)
    279.             return;
    280.         StartCoroutine(waiter());
    281.  
    282.     }
    283.  
    284.     [Command]
    285.     void CmdIsReloading()
    286.     {
    287.         RpcIsReloading();
    288.     }
    289.  
    290.     [ClientRpc]
    291.     void RpcIsReloading()
    292.     {
    293.         isReloading = true;
    294.  
    295.     }
    296.  
    297.     [Command]
    298.     void CmdIsNotReloading()
    299.     {
    300.         RpcIsNotReloading();
    301.     }
    302.  
    303.     [ClientRpc]
    304.     void RpcIsNotReloading()
    305.     {
    306.         isReloading = false;
    307.  
    308.     }
    309.  
    310.     [Command]
    311.     void CmdSetBulletsShot()
    312.     {
    313.         RpcSetBulletsShot();
    314.     }
    315.  
    316.     [ClientRpc]
    317.     void RpcSetBulletsShot()
    318.     {
    319.         BulletsShot = 0;
    320.  
    321.     }
    322.  
    323.     [ClientRpc]
    324.     void RpcNoAmmoLeft()
    325.     {
    326.         range = 0;
    327.         MuzzleFlash.SetActive(false);
    328.         audioSource.enabled = false;
    329.     }
    330.  
    331.     [Command]
    332.     void CmdShoot()
    333.     {
    334.         RpcShoot();
    335.  
    336.         Bullets -= 1;
    337.  
    338.         if (Bullets == 0 && MaxBulletCount >= 1)
    339.         {
    340.             anim.SetTrigger("isReloading");
    341.             StartCoroutine(NoAmmo());
    342.             audioSource2.clip = reload;
    343.             audioSource2.Play();
    344.             RpcReload();
    345.         }
    346.  
    347.         if (Bullets < 0)
    348.             {
    349.                 Bullets = 0;
    350.             }
    351.  
    352.         if (Bullets == 0 && BulletCount == 0 && MaxBulletCount == 0)
    353.         {
    354.             range = 0;
    355.             MuzzleFlash.SetActive(false);
    356.             audioSource.enabled = false;
    357.             RpcNoAmmoLeft();
    358.         }
    359.  
    360.         RaycastHit hit;
    361.         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    362.         {
    363.  
    364.             Debug.Log(hit.transform.name);
    365.  
    366.             Health health = hit.transform.GetComponent<Health>();
    367.  
    368.  
    369.             if (health != null)
    370.             {
    371.                 CmdHitSound();
    372.                 CmdHitMarker();
    373.  
    374.                 if (hit.collider.tag == "Head")
    375.                 {
    376.                     health.CmdTakeDamage(Random.Range(minDmgHead, maxDmgHead));
    377.                 }
    378.  
    379.                 else if (hit.collider.tag == "Torso")
    380.                 {
    381.                     health.CmdTakeDamage(Random.Range(minDmgTorso, maxDmgTorso));
    382.                 }
    383.  
    384.                 else if (hit.collider.tag == "Leg")
    385.                 {
    386.                     health.CmdTakeDamage(Random.Range(minDmgLeg, maxDmgLeg));
    387.                 }
    388.             }
    389.         }
    390.     }
    391.  
    392.     [ClientRpc]
    393.     void RpcShoot()
    394.     {
    395.         BulletsShot += 1;
    396.         BulletCount = BulletCount - 1;
    397.         SetBulletCount();
    398.     }
    399. }
    400.  
     
  8. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    And also how would I call NoAmmo on the server instead of the client?
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,041
    Just don't call it on the client :) You're already calling it on the server. Make everything that you would update in NoAmmo on the client into a syncvar if you need those values still on the client.
     
  10. Vexer

    Vexer

    Joined:
    Feb 24, 2016
    Posts:
    185
    I have this now but the problem is that if my hosts bullets are 0 it starts to reload but if the clients bullets are 0 i have to shoot one more time for it to actually reload and that also F***s up my other code so then my code resets and thinks he only shot once because if you shoot more then 15 it just resets to 0 so how do i let my client reload like my host if the bullets are 0 ?
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using System.Collections;
    5. using UnityEngine.UI;
    6.  
    7. public class Gun : NetworkBehaviour {
    8.     public Camera fpsCam;
    9.     public ParticleSystem muzzleFlash;
    10.     public ParticleSystem Tracer;
    11.  
    12.     public float damage = 10f;
    13.     public float range = 100f;
    14.     public float fireRate = 3.5f;
    15.    [SyncVar] public int Bullets = 15;
    16.     private int BulletCount;
    17.     private int MaxBulletCount;
    18.     [SyncVar] public int BulletsShot;
    19.  
    20.     public Text bulletCount;
    21.     public Text maxBulletCount;
    22.  
    23.     public bool BeforeAiming;
    24.     public bool isAiming;
    25.     public bool AfterAiming;
    26.  
    27.     public Animator anim;
    28.  
    29.     private float nextTimeToFire = 0f;
    30.  
    31.     public bool isReloading;
    32.  
    33.     public AudioClip shoot;
    34.     public AudioClip hitsound;
    35.     public AudioClip reload;
    36.  
    37.     public GameObject MuzzleFlash;
    38.  
    39.     private AudioSource audioSource;
    40.     public AudioSource audioSource2;
    41.     float speed = 0.2f;
    42.     public GameObject crosshair;
    43.     public GameObject hitmarker;
    44.  
    45.     public int minDmgHead = 45;
    46.     public int maxDmgHead = 70;
    47.     public int minDmgTorso = 15;
    48.     public int maxDmgTorso = 25;
    49.     public int minDmgLeg = 5;
    50.     public int maxDmgLeg = 10;
    51.  
    52.     public bool Idle;
    53.  
    54.     void Start()
    55.     {
    56.         audioSource = GetComponent<AudioSource>();
    57.         hitmarker.SetActive(false);
    58.         if (!isLocalPlayer)
    59.             return;
    60.         crosshair.SetActive(true);
    61.         BulletsShot = 0;
    62.             BulletCount = 15;
    63.         MaxBulletCount = 75;
    64.         SetBulletCount();
    65.         SetMaxBulletCount();
    66.     }
    67.  
    68.     // Update is called once per frame
    69.     void Update() {
    70.         if (!isLocalPlayer) return;
    71.         if (BeforeAiming == true)
    72.         {
    73.             anim.SetBool("Idle", Idle);
    74.             anim.SetBool("Idle", false);
    75.         }
    76.  
    77.         if (isAiming == true)
    78.         {
    79.             anim.SetBool("Idle", Idle);
    80.             anim.SetBool("Idle", false);
    81.         }
    82.  
    83.         if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire && isReloading == false) {
    84.  
    85.             nextTimeToFire = Time.time + 1f / fireRate;
    86.             audioSource.clip = shoot;
    87.             audioSource.Play();
    88.             CmdShootAnimation();
    89.             CmdShoot();
    90.             CmdMuzzleFlash();
    91.             muzzleFlash.Play();
    92.         }
    93.  
    94.         if (Input.GetMouseButton(1))
    95.         {
    96.             StartCoroutine(Aiming());
    97.         }
    98.  
    99.         if (!Input.GetMouseButton(1))
    100.         {
    101.             StartCoroutine(afterAiming());
    102.             isAiming = false;
    103.             anim.SetBool("isAiming", false);
    104.         }
    105.  
    106.         if (Input.GetMouseButtonUp(1))
    107.         {
    108.             AfterAiming = true;
    109.             anim.SetBool("AfterAiming", AfterAiming);
    110.             anim.SetBool("AfterAiming", true);
    111.             StartCoroutine(afterAiming());
    112.         }
    113.  
    114.         if (Input.GetMouseButtonDown(1))
    115.         {
    116.             BeforeAiming = true;
    117.             anim.SetBool("BeforeAiming", BeforeAiming);
    118.             anim.SetBool("BeforeAiming", true);
    119.         }
    120.  
    121.         if (Input.GetKeyDown(KeyCode.R) && Bullets <= 14 && MaxBulletCount >= 1 && isReloading == false)
    122.         {
    123.                 anim.SetTrigger("isReloading");
    124.             audioSource2.clip = reload;
    125.             audioSource2.Play();
    126.             StartCoroutine(NoAmmo());
    127.         }
    128.     }
    129.  
    130.     void SetBulletCount()
    131.     {
    132.         if (isLocalPlayer)
    133.         {
    134.             if (BulletCount < 0)
    135.             {
    136.                 BulletCount = 0;
    137.             }
    138.  
    139.             if (MaxBulletCount < 0)
    140.             {
    141.                 MaxBulletCount = 0;
    142.             }
    143.  
    144.             bulletCount.text = BulletCount.ToString();
    145.             maxBulletCount.text = MaxBulletCount.ToString();
    146.         }
    147.     }
    148.  
    149.     void SetMaxBulletCount()
    150.     {
    151.         if (isLocalPlayer)
    152.         {
    153.             if (MaxBulletCount < 0)
    154.             {
    155.                 MaxBulletCount = 0;
    156.             }
    157.             maxBulletCount.text = MaxBulletCount.ToString();
    158.         }
    159.     }
    160.     IEnumerator Aiming()
    161.     {
    162.         //Wait for 0.5 seconds
    163.         yield return new WaitForSeconds(0.25f);
    164.         BeforeAiming = false;
    165.         anim.SetBool("BeforeAiming", false);
    166.  
    167.         isAiming = true;
    168.         anim.SetBool("isAiming", isAiming);
    169.         anim.SetBool("isAiming", true);
    170.  
    171.     }
    172.  
    173.     IEnumerator afterAiming()
    174.     {
    175.         //Wait for 0.5 seconds
    176.         yield return new WaitForSeconds(0.1f);
    177.         AfterAiming = false;
    178.         anim.SetBool("AfterAiming", AfterAiming);
    179.         anim.SetBool("AfterAiming", false);
    180.  
    181.     }
    182.  
    183.     IEnumerator NoAmmo()
    184.     {
    185.         isReloading = true;
    186.         CmdIsReloading();
    187.         isAiming = false;
    188.             anim.SetBool("isAiming", isAiming);
    189.             anim.SetBool("isAiming", false);
    190.             range = 0f;
    191.             MuzzleFlash.SetActive(false);
    192.             audioSource.enabled = false;
    193.  
    194.             //Wait for 2 seconds
    195.             yield return new WaitForSeconds(2f);
    196.         isReloading = false;
    197.         CmdIsNotReloading();
    198.             Bullets = 15;
    199.             BulletCount = 15;
    200.         MaxBulletCount -= BulletsShot;
    201.         SetMaxBulletCount();
    202.         BulletsShot = 0;
    203.         SetBulletCount();
    204.         range = 100f;
    205.             MuzzleFlash.SetActive(true);
    206.             audioSource.enabled = true;
    207.             if (isAiming)
    208.             {
    209.                 BeforeAiming = true;
    210.                 anim.SetBool("BeforeAiming", true);
    211.             }
    212.     }
    213.  
    214.     IEnumerator waiter()
    215.     {
    216.         hitmarker.SetActive(true);
    217.         crosshair.SetActive(false);
    218.  
    219.         //Wait for 4 seconds
    220.         yield return new WaitForSeconds(0.2f);
    221.  
    222.         hitmarker.SetActive(false);
    223.         crosshair.SetActive(true);
    224.  
    225.     }
    226.  
    227.     [Command]
    228.     void CmdBullets()
    229.     {
    230.         RpcBullets();
    231.     }
    232.  
    233.     [ClientRpc]
    234.     void RpcBullets()
    235.     {
    236.         Bullets = 15;
    237.     }
    238.  
    239.     [Command]
    240.     void CmdReload()
    241.     {
    242.         RpcReload();
    243.     }
    244.  
    245.     [ClientRpc]
    246.     void RpcReload()
    247.     {
    248.         anim.SetTrigger("isReloading");
    249.         StartCoroutine(NoAmmo());
    250.     }
    251.  
    252.     [Command]
    253.     void CmdShootAnimation()
    254.     {
    255.         RpcShootAnimation();
    256.     }
    257.  
    258.     [ClientRpc]
    259.     void RpcShootAnimation()
    260.     {
    261.         anim.SetTrigger("Shoot");
    262.     }
    263.  
    264.     [Command]
    265.     void CmdMuzzleFlash()
    266.     {
    267.         RpcMuzzleFlash();
    268.     }
    269.  
    270.     [ClientRpc]
    271.     void RpcMuzzleFlash()
    272.     {
    273.         if (isLocalPlayer)
    274.             return;
    275.         muzzleFlash.Play();
    276.     }
    277.  
    278.     [Command]
    279.     void CmdShootSound()
    280.     {
    281.         RpcShootSound();
    282.     }
    283.  
    284.     [ClientRpc]
    285.     void RpcShootSound()
    286.     {
    287.         if (isLocalPlayer)
    288.             return;
    289.         audioSource.clip = shoot;
    290.         audioSource.Play();
    291.     }
    292.  
    293.     [Command]
    294.     void CmdHitSound()
    295.     {
    296.         RpcHitSound();
    297.     }
    298.  
    299.     [ClientRpc]
    300.     void RpcHitSound()
    301.     {
    302.         if (!isLocalPlayer)
    303.             return;
    304.         audioSource2.clip = hitsound;
    305.         audioSource2.Play();
    306.     }
    307.  
    308.     [Command]
    309.     void CmdHitMarker()
    310.     {
    311.         RpcHitMarker();
    312.     }
    313.  
    314.     [ClientRpc]
    315.     void RpcHitMarker()
    316.     {
    317.         if (!isLocalPlayer)
    318.             return;
    319.         StartCoroutine(waiter());
    320.  
    321.     }
    322.  
    323.     [Command]
    324.     void CmdIsReloading()
    325.     {
    326.         RpcIsReloading();
    327.     }
    328.  
    329.     [ClientRpc]
    330.     void RpcIsReloading()
    331.     {
    332.         isReloading = true;
    333.  
    334.     }
    335.  
    336.     [Command]
    337.     void CmdIsNotReloading()
    338.     {
    339.         RpcIsNotReloading();
    340.     }
    341.  
    342.     [ClientRpc]
    343.     void RpcIsNotReloading()
    344.     {
    345.         isReloading = false;
    346.  
    347.     }
    348.  
    349.     [Command]
    350.     void CmdSetBulletsShot()
    351.     {
    352.         RpcSetBulletsShot();
    353.     }
    354.  
    355.     [ClientRpc]
    356.     void RpcSetBulletsShot()
    357.     {
    358.         BulletsShot = 0;
    359.  
    360.     }
    361.  
    362.     [ClientRpc]
    363.     void RpcNoAmmoLeft()
    364.     {
    365.         range = 0;
    366.         MuzzleFlash.SetActive(false);
    367.         audioSource.enabled = false;
    368.     }
    369.  
    370.     [Command]
    371.     void CmdShoot()
    372.     {
    373.         RpcBulletsClient();
    374.         RpcShoot();
    375.  
    376.         Bullets -= 1;
    377.  
    378.         if (Bullets < 0)
    379.             {
    380.                 Bullets = 0;
    381.             }
    382.  
    383.         if (Bullets == 0 && BulletCount == 0 && MaxBulletCount == 0)
    384.         {
    385.             range = 0;
    386.             MuzzleFlash.SetActive(false);
    387.             audioSource.enabled = false;
    388.             RpcNoAmmoLeft();
    389.         }
    390.  
    391.         RaycastHit hit;
    392.         if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    393.         {
    394.  
    395.             Debug.Log(hit.transform.name);
    396.  
    397.             Health health = hit.transform.GetComponent<Health>();
    398.  
    399.  
    400.             if (health != null)
    401.             {
    402.                 CmdHitSound();
    403.                 CmdHitMarker();
    404.  
    405.                 if (hit.collider.tag == "Head")
    406.                 {
    407.                     health.CmdTakeDamage(Random.Range(minDmgHead, maxDmgHead));
    408.                 }
    409.  
    410.                 else if (hit.collider.tag == "Torso")
    411.                 {
    412.                     health.CmdTakeDamage(Random.Range(minDmgTorso, maxDmgTorso));
    413.                 }
    414.  
    415.                 else if (hit.collider.tag == "Leg")
    416.                 {
    417.                     health.CmdTakeDamage(Random.Range(minDmgLeg, maxDmgLeg));
    418.                 }
    419.             }
    420.         }
    421.     }
    422.  
    423.     [ClientRpc]
    424.     void RpcBulletsClient()
    425.     {
    426.         if (Bullets == 0 && MaxBulletCount >= 1)
    427.         {
    428.             anim.SetTrigger("isReloading");
    429.             StartCoroutine(NoAmmo());
    430.             audioSource2.clip = reload;
    431.             audioSource2.Play();
    432.         }
    433.     }
    434.  
    435.     [ClientRpc]
    436.     void RpcShoot()
    437.     {
    438.         BulletsShot += 1;
    439.         BulletCount = BulletCount - 1;
    440.         SetBulletCount();
    441.     }
    442. }
    443.