problem with instantiate function

i am having a problem with instantiating bullet in my project. when i call the fire then it instantiate three bullet at a time. i don’t know what is the problem. please someone help me.

the code is:

function Fire () {
    // Did the time exceed the reload time?
    if (Time.time > reloadTime + lastShot && ammoCount > 0 && count>0) {
        if(count <= 0){
            yield WaitForSeconds(2.0);
            count = resetcount;
        //guitexthint.message = count;
        // create a new projectile, use the same position and rotation as the Launcher.
        var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
        // Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
        instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

        // Ignore collisions between the missile and the character controller
        Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
        lastShot = Time.time;


The code you presented will only spawn at most one projectile for each call to Fire(). So either there is a problem in your calling function, calling Fire() more than once, or it is a delayed reaction:

If count is <=0 after you decrease it, you wait for two seconds, and then fire a shot, no matter what.

However, this problem depends on the value of “resetcount” (and the initial value of “count”). If it is 1, one call to Fire() (assuming you have ammo and realoadTime has passed) will be delayed by 2 seconds, then one shot will be fired. Calling Fire() again in the meantime will do nothing. If it is 2, one call to Fire() will fire immediately, and then the same happens as with 1, and so on.

What is your intention of using this counter named “count” and delaying the shot by two seconds?

thanks for your reply . i have set the vales of resetcount and count to 30, so that after every 30 bullet it will wait for 2 seconds. but i don’t know why it is firing more than one projectile/bullet on every call to the fire function