- Home /
Instantiating Muzzle Flash
I want to create a muzzle flash for my gun, and I incorporated it into my shoot script. Here's an excerpt:
if(Input.GetButton("Fire1") && Time.time > nextFire && bulletsLeft > 0 && !boosting) {
nextFire = Time.time + fireRate;
Instantiate (projectile, shootPointOne.position, transform.rotation);
Instantiate (muzzleFlash, shootPointOne.position, transform.rotation);
hasFired = true;
}
It all works except for the muzzleFlash. The muzzleFlash is a Texture2D and this seems the most logical way for making a muzzle flash without animations. Is this the correct way to approach this, or is their a better, more direct way?
You need to make it a plane, with the texture on it (with transparency). Then, put some fade out and destroy script on the flash prefab.
Answer by Owen-Reynolds · Oct 18, 2011 at 02:20 PM
The easiest way to get a "pulse" of a texture is to put it in a particle emitter (which will automatically give it a life-time then kill it.)
To put in the Texture, you can drag it to the bottom of a particle emitter. You should see the material, in ParticleRenderer, update from the white ball to your texture. If that messes up the colors, click on shader where it says "Particles/AlphaBlended" and pick another one from the Particles folder.
To make it appear then die, click (far above) OneShot and AutoDestruct. Then tweak it so it looks nice (size, life -- see the PE docs.)
Alright, looks great, except for the muzzle flash texture, which has nothing to do with your answer, so thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220613012905im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hey can anyone help with a shooting script??? 0 Answers
How to shoot with swipe? 0 Answers
Muzzle Flash Not Working 0 Answers