Search Unity

How Pick up Clips for reload ammo

Discussion in 'Scripting' started by Giannigiardinelli, Nov 21, 2014.

  1. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    189
    After more research I have not found the solution, making a response PaxNemesis I thank btw who give a script here on the site reloading of ammo I took the idea for his script only if the player supports several times on the "R" key it gets ammunition at will, and if he picks up ammo and reload it loses all the ammunition that the pick ...
    What I seek is the ability to pick clips that give ammunition when the player input "R"
    For example, I 5Clips 10Munition and I reload and I 4clips and 50Munitions
    here is the script to publish PaxNemesis

    So how to pick the clips that come in the script to add that when you press the R using the following?

    Code (csharp):
    1.  int count = 8;
    2.      bool reloading = false;
    3.  
    4.      void Update()
    5.      {
    6.          if (Input.GetKeyDown(KeyCode.R))
    7.              Reload();
    8.  
    9.          // Should only be able to shoot if we aren't reloading and still have ammo.
    10.          if (!reloading && count > 0 && Input.GetButtonDown("Fire1"))
    11.              Shoot();
    12.      }
    13.  
    14.      void Shoot()
    15.      {
    16.          // Do shooting stuff.
    17.          --count;
    18.  
    19.          // If we used our last shot, then we should reload.
    20.          if (count <= 0)
    21.              Reload();
    22.      }
    23.  
    24.      void Reload()
    25.      {
    26.          reloading = true;
    27.          
    28.          // Do reloading stuff.
    29.          count = 8;
    30.  
    31.          reloading = false;
    32.      }