Muzzle Flash

I have a texture of a muzzle flash and i’m going to apply it to an object, the thing i’m wondering is how do i make the object’s rendering enable and disable rapidly while the mouse is held down.

Here is one solution. I imagine you want to start with the renderer for the flash graphic disabled:

#pragma strict

var speed = 20.0;

function Update() {
	if (Input.GetMouseButton(0)) {
		renderer.enabled = (Mathf.PingPong(Time.time * speed, 1.0) < 0.5);
	}
	if (Input.GetMouseButtonUp(0)) {
		renderer.enabled = false;
	}
}