- Home /
How to change the fire rate on my shooting script?
I have a script and I want to change the fire rate to a slower rate. Maybe 7 or 8 rounds a second.
#pragma strict
var bullet : GameObject;
var bulletsPerSecond = 1.0;
private var shooting = false;
function Start() {
InvokeRepeating("Shoot", 0.0, 1.0 / bulletsPerSecond);
}
function Shoot() {
if (!shooting) return;
var go = Instantiate(bullet, transform.position, transform.rotation);
go.rigidbody.AddRelativeForce(Vector3.forward * 1750.0);
}
function Update(){
shooting = false;
if(Input.GetAxis("Fire1")){
shooting = true;
}
}
What can I do? Thanks
Answer by robertbu · Jan 17, 2014 at 02:33 AM
This script was copied from this answer:
http://answers.unity3d.com/questions/497600/change-gun-fire-rate.html
And I answered your comment asking this same question:
@TheReclaimer117 - in Javacript, variables are public by default. That means after the script is attached, any changes to the initialization of a variable in script are ignored. You can either select the game object this script is attached to and then adjust the value in the inspector, or you can make the variable private:
private var bulletsPerSecond = 14.0;
Yeah I saw and did that code. I replaced my original bullets per second = 14 or whatever and added yours and set it to 8. Thanks so much. Now I add ammo and reloading and my gun is done. Thanks!
Your answer

Follow this Question
Related Questions
Enemy fire rate? help! 2 Answers
how to add firerate to enemies shooting script 0 Answers
Firerate problem 2 Answers
How to change the speed of a projectile? 2 Answers