- Home /
How to make a gun shoot in burst.
Hello, you. Yes you!
I have searched a little bit, but I am unable to find and questions or answers about "Bursts". For those that do not know burst are(in this case) 3 shot fired with just a slight delay between each other when the trigger is pulled.
I tried something like this:
var sound : AudioClip;
function Shoot () //Ran from function Update.
{
audio.PlayOneShot(sound);
yield WaitForSeconds(0.2);
audio.PlayOneShot(sound);
yield WaitForSeconds(0.2);
audio.PlayOneShot(sound);
}
But no luck now the function wont execute at all, but even if it did it will look ugly and "not cool". I know I can use for´s for(var blah blah), but there is no delay between those.
So dear community is there a way in a relatively easy manner that we can create a burst effect?
Legion.
Answer by flaviusxvii · Jul 06, 2011 at 08:12 PM
I would do something like this:
int burstShots = 0;
float burstTimer = 0.0;
float burstDelay = 0.0;
function Update()
{
if(burstShots > 0) {
if(burstTimer <= burstDelay) {
// play the sound or whatever
burstTimer = burstDelay;
burstShots -= 1;
} else {
burstTimer -= Time.deltaTime;
}
}
}
Answer by Coreyf716 · Feb 23, 2013 at 09:50 PM
You could also use the 'while' loop:
int i = 3;
float waitTimer;
while (i > 0 && waitTimer <= 0) {
audio.PlayOneShot(sound);
waitTimer = 0.2f;
}
Your answer
Follow this Question
Related Questions
Shoot Bullet Delay Enemy 0 Answers
Aim at Something with Delay 1 Answer
Shoot Delay in C# 1 Answer
C# Enemy shoot on timer 1 Answer
keybind problem 0 Answers