Help for muzzle flash script

Hi, i’m not good at scripting so i was thinking about if anyone could write a script too me so i can have two muzzle flashes with (one) gun, because my model have dual wielded pistols so i need two muzzle flashes.

I have seen that people have used particles and prefabs to make some muzzle flashes on this (forum) but I haven’t got them to work.

Thanks in advance :slight_smile:

I do agree with the statement of CrhisD but thought I’d try to give you a push in the right direction. Basically you create a Particle System and set the emitter options to your liking, preferably add some random velocity so it never looks the same and set it to One Shot and Autodestruct. Make a prefab out of it and then via script instantiate:

var muzzleFlash : ParticleEmitter; //Your emitter prefab
var gunEnd : Transform; //An empty gameobject positioned at the end of the gun as a child
var gunEnd2 : Transform; //Same as above but the other one

//Call OnShooting() from somewhere in your firing script
function OnShooting () {
    Instantiate(muzzleFlash, gunEnd.position, gunEnd.rotation);
    yield WaitForSeconds (0.2);
    Instantiate(muzzleFlash, gunEnd2.position, gunEnd2.rotation);
}

Just a very basic example. Perhaps a switch and a more precise timer in between shots later on would be a good idea. Inside the function you can call for sounds, light and so forth. Hopefully this can get you started though.