Adding a muzzle flash to this different script?

So I made this script used the rocket launcher example from the fps tutorial, and i wanted to add a muzzle flash. Im trying to take the concept from the machine gun’s muzzle flash and some how adding it into the launcher’s one, but it just doesn’t seem to work.

Heres my updated script:

var launchPos : Vector3; 
var projectile : Rigidbody; 
var initialSpeed = 20.0; 
var reloadTime = 0.5; 
private var lastShot = -10.0; 

var muzzleFlash : Renderer; 

var reloadRealTime = 5; 
var bulletsPerClip = 100;
static var bulletsLeft : int = 100; 
static var clipsLeft : int = 2; 

var isReloading : boolean = false;

var fireRate = 0.05; 

private var nextFireTime = 0.0; 

function LateUpdate() { 

   if(Input.GetButtonDown("Reload")  clipsLeft >= 1  isReloading == false) 
   Reload(); 
   }
   
function Fire () {

   if (bulletsLeft == 0  clipsLeft >=1  isReloading == false) { 
     Reload(); 
     return; 
 }

   // Did the time exceed the reload time? 
   if (Time.time > reloadTime + lastShot  bulletsLeft > 0) 
   { 
    
    //Fix the launch position of the rocket 
   var launchPos : Vector3 = transform.TransformDirection(new Vector3(0.5, 0, 3)); 
    // create a new projectile, use the same position and rotation as the Launcher. 
    var instantiatedProjectile : Rigidbody = Instantiate (projectile,transform.position + launchPos, transform.rotation); 

    // Give it an initial forward velocity. The direction is along the z-axis of 
    // the rocket launcher's transform. 
    instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, initialSpeed)); 

   // Ignore collisions between the rocket and the character controller 
   Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider); 
   lastShot = Time.time; 
   FireOneShot();
   } 
}

function FireOneShot () { 
//decrease bullets by 1. 
   bulletsLeft--; 
      //gun reload in time 
   if (bulletsLeft == 0  clipsLeft >=1  isReloading == false) { 
     Reload(); 
    }
} 

function Reload (){ 
if (!isReloading) 
{
isReloading = true;

SendMessageUpwards("setEnableWeaponSwitch", false); 
//audio.PlayOneShot(reloadSound, 1.0 / audio.volume); 
//   Wait for reload time first - then add more bullets! 
yield WaitForSeconds(reloadRealTime); 
   // We have a clip left reload 
 if (clipsLeft > 0 ) { 
   clipsLeft--; 
     bulletsLeft = bulletsPerClip; 
   }
SendMessageUpwards("setEnableWeaponSwitch", true); 
}
isReloading = false;
} 

static function GetBulletsLeft () { 
   return bulletsLeft; 
} 

static function GetClipsLeft () { 
return clipsLeft; 
}

Any ideas? Thanks in advance.

bumpity bump :S

have you tried just stealing the original script then changing it in the places where its necessary? or is that what youve done?

Yeah already tried it, and the results end in catastrophy, like some times it wont even shoot at all, or the muzzle flash get frozen, so im not sure how to add in muzzle flash.

i’m going to bed now, and i wish i could help more - but if the muzzle flash is getting frozen maybe you should have another function running constantly to see if its on, like every second itll check if its on and switch it off if it is - the muzzleflash wont need to be on for more than a second so that should work! :smile: ill see if i can help some more tomorrow.

oh alright thanks ill try it

To run a function repeatedly, but not on every update, you can use InvokeRepeating. (I just discovered it last week. Check it out in the Unity Scripting documentation.)