Unity3D GetButtonDown aint working

Hello, Im trying to write a gun script here, I’ve checked the unity Script reference and thats where I got this idea from, and I got a problem, Im trying to reload my gun when ammo is equal to zero but I get no errors at all from that but it wont reload at all…

posting my script

public class Shoot : MonoBehaviour {
	public Rigidbody Bulletprefab;
	public Transform barrelEnd;
	public int ammoPerClip = 8;
	public int Clips = 5;


	void Update () 
	{
		if(Input.GetButtonDown("Fire1"))
		{
			if(ammoPerClip > 0)
			{
				Rigidbody bulletInstance;
				bulletInstance = Instantiate(Bulletprefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
				bulletInstance.AddForce(barrelEnd.forward * 3000);
				ammoPerClip--;
			}
			if(ammoPerClip <= 0)
			{
				return;
				ammoPerClip = 0;

			}
			if(ammoPerClip == 0)
			{
				if(Input.GetKeyDown(KeyCode.R))
				{
					ammoPerClip = 8;
					Clips--;
				}
			}
		}
	}
}

Im not done with the script yet, I just started working on it and I got stuck on the reloading part.

You return before setting the ammoPerClip to 0 so your code will never reach the if(ammoPerClip == 0) part of your script. I think you’d best move the check if the ammoPerClip is empty outside the check for the fire button being pressed (right now, if this would work, you’d need to press Fire1 and R to reload).

So something more like this:

void Update () 
{
	if (ammoPerClip == 0)
	{
		if (Input.GetKeyDown(KeyCode.R))
		{
			ammoPerClip = 8;
			Clips--;
		}
	}

	if (Input.GetButtonDown("Fire1"))
	{
		...
	}
}

You could, of course, combine the if (ammoPerClip == 0) and if (Input.GetKeyDown(KeyCode.R)) to if (Input.GetKeyDown(KeyCode.R) && ammoPerClip == 0).

Here, check this:

public class Shoot : MonoBehaviour {
    public Rigidbody Bulletprefab;
    public Transform barrelEnd;
    public int ammoPerClip = 8;
    public int Clips = 5;
 
 
    void Update () 
    {
       if(Input.GetButtonDown("Fire1"))
       {
         if(ammoPerClip > 0)
         {
          Rigidbody bulletInstance;
          bulletInstance = Instantiate(Bulletprefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
          bulletInstance.AddForce(barrelEnd.forward * 3000);
          ammoPerClip--;
         }
         if(ammoPerClip <= 0)
         {
          return;
          ammoPerClip = 0;
 
         }
       }
         // I've put this outside Fire loop. That's it.
         if(ammoPerClip == 0)
         {
          if(Input.GetKeyDown(KeyCode.R))
          {
              ammoPerClip = 8;
              Clips--;
          }
         }
    }
}

All you were doing was to check if Fire button is pressed then if user presses R key while Fire button is pressed then it should reload. I made it so that Reload is independent of Fire key.

Cheers!