- Home /
adding a delay to shooting
I have tried various methods but the if adding a value for the variable burstdelay doesn't have any effect on slowing down shooting I'm stuck anyone that can help would be appricated.
if(burstTimer < burstDelay)
{
ERayShoot();
audio.PlayOneShot(ShootSound);
_hit.collider.SendMessageUpwards("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
BulletsLeft--;
// play the sound or whatever
burstTimer = burstDelay;
}
else
{
burstTimer -= 0.1f;
}
I posted a answer, it will take some time to post up. Dang mods...
Where have you written the ERayShoot() function. You are just calling it. And what function are writing all these in?
Answer by Fabkins · Apr 25, 2012 at 03:39 AM
Try:
if(Time.time > ( lastFireTime + burstDelay) )
{
lastFireTime=Time.time;
.......
}
Setting burstDelay to 0.5 will give you a 1/2 second delay.
Thanks alot will credit you on my dissertation, amazing thanks alot
No worries, hardly warrants creditation , well appart from the fact I did it on an iPad with autocorrect which made for fun coding,..lol
Ps if thats answered your question mark it as answered so other people know at glance on the summary.
Answer by maroonrs2 · Apr 25, 2012 at 06:00 AM
var activated:boolean = true;
function Update()
{
if(activated)
{
activated = false;
cour();
}
}
function cour()
{
yield waitDelay()
activated = true;
}
function waitDelay()
{
yield waitForSeconds (5); //Here it waits 5 seconds.
}
This is called a coroutine. It delays using functions, since there is no other delay method.
Your answer
Follow this Question
Related Questions
Reload Ammo is not working 1 Answer
Reload Ammo is not working 0 Answers
Shot Delay between button press. c# 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers