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).