I’m wanting to create a boss fight and I’m using states to do it. I want one of the functions in my state to fire 3 bullets only at the player but one after the other so they don’t collide with each other and come out all at once. Sadly i don’t know how to do this.
I did try and it just ended up with the bullets coming out all at once instead of one after the other like i wanted.
var timer:float;
var gunnumber:int;
var bulletonce:int;
var delay:float; //----time between shots
if(Input.GetKeyDown("space")){gunnumber=3;timer=3;}
if(gunnumber>0){
timer=timer-Time.deltaTime*delay;
if(timer<0){timer=3;
gunnumber=gunnumber-1;}}
if(gunnumber!=bulletonce){
bulletnumber=bulletonce;
//----------------------trigger a bullet here however you are doing that. lol!!!!!!
}}
You could add a delay in between firing the bullets like this:
var delayTime = 0.5;
var startTime = Time.time;
while (Time.time - startTime < delayTime)
{
yield;
}
Note that the yield statement will technically make your function into a coroutine. As a result, this will be slightly more complicated to implement in C#. See here for more on coroutines. There may be other ways to achieve this functionality if this route seems unappealing to you.