bullet counting problem

Hi, I’ve got a script for the amount of ammo for my character, but when he’s reloading in the script can i shoot in the game. I want my character not to shoot when reloading. Can someone help me? here’s my script:

    // It needs to know how many bullets (rounds) one clip can hold
var magazineCapacity = 30;

// It needs to know how many rounds are left in the current magazine (clip)
var remainingRounds = 30;

// Then setup your `Fire` function
public function Fire ()
{
    if (remainingRounds > 0) { // we still have bullets left, fire away!
        // ...
        // Instantiate your bullets/missiles/plasma blasts/teddy bears here
        // ...
        remainingRounds -= 1; // remove that bullet from the magazine
    } else { // we're out
        // ...
        // play the classic "click, click" out of ammo sound
        // or however you want to notify the user they need to reload
        // Prints 0
		print (Time.time);
		// Waits 5 seconds
		yield WaitForSeconds (5)
		// Prints 5.0
		print (Time.time);
        // ...
        Reload();
        // if the user forgets to reload go ahead and do it
                  // for them when they try to shoot again
    }
}
// Then attach an input to that function
public function Update ()
{
    // ...
    if ( Input.GetButtonDown( "Jump" ) ) { Fire(); }
    if ( Input.GetButtonDown( "reload" ) ) { Reload(); }
    // ...
}

// Then you'll need that `Reload` function we used a minute ago
public function Reload ()
{
    // ... trigger the reload animation
    remainingRounds = magazineCapacity; // put in a new clip
}

and there is another thing how do i say in the script that when i press the ‘r’ button he’s going to reload?

THANKS!

I generally use something like that but i don’t know will it work on your script, do something like that:

var a = 0;

if(a==0){
 if (remainingRounds > 0) { // we still have bullets left, fire away!
        // ...
        // Instantiate your bullets/missiles/plasma blasts/teddy bears here
        // ...
        remainingRounds -= 1; // remove that bullet from the magazine
    } else { // we're out
        // ...
        // play the classic "click, click" out of ammo sound
        // or however you want to notify the user they need to reload
        // Prints 0
        print (Time.time);
        // Waits 5 seconds
        yield WaitForSeconds (5)
        // Prints 5.0
        print (Time.time);
        // ...
        Reload();
        // if the user forgets to reload go ahead and do it
                  // for them when they try to shoot again
    }
    }

And in your Reload function, before the anim start just say a=1; , which means you wont be able to shoot because you need a to be 0 to shoot, and after the animation code just put a=0; to make it shootable ( lets say :stuck_out_tongue: ) again.

Edit : And i see you are not using any animation code, so you can do the same thing to
this :

remainingRounds = magazineCapacity;

it doesn’t matter, even you can do something like that ;

a=1; // we are not able to fire
yield WaitForSeconds(2); // the reload takes 2 seconds to fire
a=0; // we can shoot again

Have use to see is reloading.

var magazineCapacity = 30;
var reloadTime = 3;
var dryFireSound : AudioClip;
var isReloading = false;
private var remainingRounds : int;

function Start ()
{
	remainingRounds = magazineCapacity;
}

function Fire ()
{
    // Instantiate your bullets/missiles/plasma blasts/teddy bears here
    remainingRounds -= 1;
    Debug.Log("Remaining Rounds = " + remainingRounds);
    if (remainingRounds <= 0) Reload();
}

function Update ()
{
    if ( Input.GetButtonDown( "reload" ) && !isReloading)
    {
	    Reload();
    }

	if (remainingRounds > 0 && !isReloading)
    {
        if ( Input.GetButtonDown( "Jump" ) )
        {
        	Fire();
        }
    }
    else
    {
	    if ( Input.GetButtonDown( "Jump" ) )
        {
		    audio.PlayOneShot(dryFireSound);
	    }
    }
}

function Reload ()
{
    isReloading = true;
    yield WaitForSeconds (reloadTime);
    remainingRounds = magazineCapacity;
    isReloading = false;
}

@script RequireComponent (AudioSource)