Making A 4 Barrel ShotGun! Need Some Help - UPDATE

Hello,

I'm making a 4 barrel shotgun turret, and basically all I want it to do is fire each barrel one second after one another. Well, when I say fire, I mean for a muzzle flash texture to appear infront of each barrel.

var currentBarrel : int = 0;

var muzzleFlash : GameObject[];

function Awake(){
    muzzleFlash[0].gameObject.SetActiveRecursively(false);
    muzzleFlash[1].gameObject.SetActiveRecursively(false);
    muzzleFlash[2].gameObject.SetActiveRecursively(false);
    muzzleFlash[3].gameObject.SetActiveRecursively(false);
}

function Start(){
    Timer();
}

function BarrelFlash(){
    muzzleFlash[currentBarrel].gameObject.SetActiveRecursively(true);
    yield WaitForSeconds(0.1);
    muzzleFlash[currentBarrel].gameObject.SetActiveRecursively(false);
}

function Timer(){
    while(currentBarrel < 4){
        BarrelFlash();
        yield WaitForSeconds(0.3);
        currentBarrel ++;

    }
}

This is nearly working ... it fires all the barrels in the correct sequence, but how do I then repeat it again? So it goes from: Barrel 1 ... then 2 ... then 3 ... then 4, and then just stops, how do I keep looping?

If someone could help me out with this, then I would much appreciate it.

Thanks

Just modify your existing loop a little bit:

function Timer(){
    while(true) {
        BarrelFlash();
        yield WaitForSeconds(0.3);
        currentBarrel = (currentBarrel + 1) % 4;    
    }
}

you could make a prefab and just put a remove after say a 1/5 of a second and istatate it every second and make the prefab have a point light component. yes no??

It would make more sense to have a barrel object that manages it's muzzle flash, relative to itself. Then attach 4 of these barrels to a "gun" or "barrel controller" or something with an appropriate name and function. Then have that piece fire them in sequence.

Read up on Object Oriented Programming. It is often very beneficial to recognize the objects in your program and write the code to encapsulate the individual parts. That way you could easily add a 3 or 5 barreled gun with very little work.