Gun Muzzle Flash

I know there’s a lot of questions about this topic but ive tied nearly all of them and non have worked. Can anyone tell me how I could make a muzzle flash occur whenever the player presses the left mouse button? Ive heard that you make a plane and add a muzzle flash texture onto which I have done but I don’t know how to code it.

2 Answers

2

you can do the fps turorial from unity they cover how to use muzzle flashes

Unity doesn’t support the standard 2 billboard solution as well – you could write it custom using a LineRender and a plane. But, a standard particle effect can make a nice one, if you know the settings (I’m skipping soem of the obvious ones, like Size):

Shrink the Ellipsoid (where they spawn from,) set OneShot and Autodestruct. Set localVelocity z to 5 or so and random x/y/z to about 3 (setting z to 3 will make the real z velocity random 2-8.) Set min/max life to around 0.1 or less (1/10th sec is 6 frames.) Go down and set StretchParticles to Stretch and LengthScale to negative (it stretches particles backwards along the way they are moving, to give a trail. Flipping to neg makes the particles stretch forwards.) Should get a quick cone.

To get it more jaggy (this is the part everyone using Emitters really need to know) make your own particle material: create a texture with a flatish bottom and jaggy top (like grass.) Put in a material, set the shader to Particles/AlphaBlended (or try the other ones near it.) Swap the material into your Emitter (replaces DefaultParticle.)

I assume you are spawning a bullet Prefab, using Instantiate from an empty at the end of the gun. Do it again for the "flash" Particle Emitter.

If you think Particle Emitters are worth looking into for various flashes, flames, smoke... then look them up in the manual -- ElipsoidParticleEmitter is the official name. If you can't figure out how to do something after that, ask another Q, saying what you've already tried.