Shooting made realistic

function fire(){

//look at the target

transform.LookAt(target);
//firing comes in //
 thebullet = Instantiate(prefalbullet, this.transform.position, this.transform.rotation);
			
			thebullet.rigidbody.AddForce(this.transform.forward *forwardForce);

 


}

I want the shooting to look more realistic…Like this script just goes on firing the bullets one after the other…

What I want to achieve is that there should be a minimum time delay(say 2-3 secs) between 2 shots being fired…
Can anyone suggest how do I modify this code to achieve this?

I don’t code in js, so I won’t modify your code, but the general procedure would be to save the Time of the previous shot, then check how long it has been since that shot on subsequent shots:

public class YourShootingScript
{
    float lastShot;


    public void Fire()
    {
        if (Time.time > lastShot + 2)
        {
            lastShot = Time.time;
            // your awesome firing script
        }
        else
        {
            // player can't shoot now, maybe I should do something?
        }
        



    }
}

Thanks a lot :slight_smile: