- Home /
Only 2 Grenades
How can I make my grenade be throw-able only 2 times in every 1 seconds.
Felipe
Answer by aldonaletto · May 26, 2012 at 07:01 AM
Every time you throw a grenade, set a dead time of 0.5 seconds - for instance:
var deadTime: float = 0;
function Update(){ if (Time.time > deadTime){ // only check input when dead time has passed if (Input.GetButtonDown("Fire1")){ // if fire button pressed... deadTime = Time.time + 0.5; // update dead time... // and throw the grenade } } }
Just a quick question, do you memorise the scripting(what to put where to put) in your head or you research it.
Well, I remember lots of Unity functions, but most times I re-check them in the docs before posting a new answer (which arguments, in which order etc.). The logic is easier due to a looong experience in program$$anonymous$$g - I wrote my first lines of code more than 30 years ago, when 99% of the UA posters were not even born (too much time for my taste...). Sometimes I must google for more complicated algorithms, but the simpler ones come directly from memory.
Answer by tatelax · May 26, 2012 at 03:18 AM
Check if the grenade was thrown 2 times in less than or equal to 1 second.
if grenade is instantiated, grenades ++