How to make a muzzle flash

I already use bullets in my game, but i am seriously thinking that i need to change it to muzzle flash, because my actual system requires a high powerfull hardware and do a big size change to my FPS.

Is there a tutorial or something to make a muzzle flash particle? Everything i tried until now failed and i want something real.

The Angry Bots demo has a perfect example of using a pyramid mesh with a ‘muzzle flash’ texture, and a script to rotate the mesh while the gun is being fired.

From the Angry Bots demo :

The ‘muzzle flash’ mesh is a child of the gun, positioned at the end of the barrel. Also note the rotation, as this will determine what axis the mesh is rotated on in the script.

Now there is a script called MuzzleFlashAnimate.js. Quite simply :

#pragma strict

function Update () {
	transform.localScale = Vector3.one * Random.Range(0.5,1.5);
	transform.localEulerAngles.z = Random.Range(0,90.0);
}

Per frame (Update), this randomly : scales the object; rotates the object on the Z axis.

Now in the firing script AutoFire.js, this can be heavily abbreviated to just :

var muzzleFlashFront : GameObject;

function Start()
{
	muzzleFlashFront.SetActive (false);
}

function Update ()
{
	if(Input.GetButtonDown("SHOOT"))
	{
		muzzleFlashFront.SetActive (true);
	}

	if(Input.GetButtonUp("SHOOT"))
	{
		muzzleFlashFront.SetActive (false);
	}
}

If the shoot button is pressed, enable the muzzleflash gameobject. If the shoot button is released, disable the muzzleflash gameobject.

When the muzzleflash object is enabled, the script MuzzleFlashAnimate starts working, and the muzzleflash effect is rotated and scaled, creating the illusion of a muzzleflash.

This is the simplest way of achieving the effect. But very effective, as stated in the original answer by Cherno (you could expand on this basic method as described by Cherno).

Gabemeister1201 explains on how to do it, it’s quite simple: (Old - Unity 5) Let's Make Rust! Episode 17 - [Muzzle Flash & Ammo System] - YouTube watch from 0:00 to 7:25.

First of all, I don’t recommend using particles for a muzzle flash effect. The reason is that particles are only shown from one angle, and muzzle flashes in real life typically don’t look like a ball of fire but rather like a longish flame spurting out of the barrel, plus additional flashes depending on the muzle break or flash hider on the gun.
Most games use a combination of planes with alpha-masked textures on them, it’s what I used for my sentry gun:

alt text

Just two planes perpendicular to each other with a long flash, and another one at flat against their “base” witha round flash one for where the bullet leaves the barrel.

For the issue of rapid fire, see this thread:

(Rapid fire) How to accurately wait for a very short amount of time?