|
Hey guys. I'm quite the n00b in Unity but im slowly getting more comfortable with it. I've since a few hours ago, run into a small problem, well 2 problems actually, but they are both practically identical, so the answers from this should help me fix the 2nd problem. Problem: when I use (Input.GetKey("z")) to fire my weapon, my bullets fire out like crazy, I understand this to be because the bullets fire with each update call, which is every frame. However I'm trying to find a way to have the bullets STOP firing for a second before firing again, so its not as much as a constant stream of bullets. My code, is as follows, this is an expansion of the 3DBUZZ video series, so that code is used as my base.
public class Player : MonoBehaviour {
} > Blockquote
(comments are locked)
|
|
The easiest way to do this is to keep track of when the last bullet was fired: Thanks man, that worked like a Charm. Works perfectly now. However Could you please example quite what "lastFired" does, changing it to any value appears to make no difference, however changing it to 100 instead of -100 causes the bullets to not fire at all. Thanks once again.
Aug 30 '10 at 05:24 PM
squall_789
lastFired is just the last time a bullet was fired. If it started at zero, you wouldn't be able to fire for a moment, until firingRate seconds had passed. When you set it to 100, you can't fire until the game has played for more than 100 seconds. I should actually have made firingRate public, as it is a value you might want to tweak.
Aug 30 '10 at 05:42 PM
Daniel Brauer
(comments are locked)
|
