- Home /
Firing things really fast?!
So in my game, I have a bullet fire script. Here's the part that controls the timing:
static var rate:int = 40;
//BulletShot function
function Update()
{
timer++;
if(Input.GetMouseButton(0) && timer > rate)
{
BulletShot();
timer = 0;
}
}
The problem is that when I run the exported game, and I have it at a low graphics setting, your fire rate is STUPIDLY fast. Is there any easy way I can fix this?
Answer by Meater6 · Sep 03, 2013 at 05:05 PM
Well, if your rate is less than 1, it will fire every frame. Update runs every frame, so when 1 frame passes, timer increases by 1.
What you probably want to do is:
timer += Time.deltaTime;
This allows you to control the time between shots, not the frames between shots.
I hope this helps! :)
Thank you! This worked, but I had to make it "timer += Time.deltaTime * 60" because it went waaaay too slow.
The rate is by default set to 40. I should probably add that.
Um, if that works for you, it should be fine. What you have done is every 2/3 or (40/60) seconds pass, you fire. I would actually decrease your rate to something like 0.5, and leave the timer alone.
Just my opinion, do what you want.
Your answer
Follow this Question
Related Questions
Setting Quaternion , are Euler angles updated in the same update function? 2 Answers
Unity Mouse Position Raycasting from Point 0 Answers
Issues using GetComponent 1 Answer
BCE0023 Error 1 Answer