Two Quick Questions

So I think both of these questions are quite simple but I may be overthinking them. The first one is, how would I enable a particle system along with my muzzle flash and light through this script? I tried the same thing I used for the renderer and light but it didn’t work.

Script

var MuzzleFlash : Renderer;
var MuzzleLight : Light;

function Start ()
{
 MuzzleFlash.enabled = false;
 MuzzleLight.enabled = false;
}

function Shoot ()
{
 MuzzleFlash.renderer.enabled = true;
 MuzzleLight.enabled = true;
 yield WaitForSeconds(0.02);
 MuzzleFlash.texture.enabled = false;
 MuzzleLight.enabled = false;
}

My second question is, how would I be able to make my gun spread less when I am aiming down the sights of my gun?
(for the shoot script area I only pasted a small piece of it [where the shooting actually happens])

Shoot Function Script

var hit : RaycastHit;
 
 ////////////////////////////INACCURACY////////////////////////////////////////////////////////////////////////////
 var DirectionRay = Vector3.Slerp (transform.TransformDirection(Vector3.forward), Random.onUnitSphere, inaccuracy);
 ////////////////////////////INACCURACY////////////////////////////////////////////////////////////////////////////
 
 var obj = Instantiate (Trail, transform.position, Quaternion.identity) as GameObject;
 
 obj.rigidbody.AddForce (DirectionRay * Force, ForceMode.VelocityChange);
 
 Debug.DrawRay(transform.position, DirectionRay * Range, Color.red);     
 if(Physics.Raycast(transform.position , DirectionRay , hit, Range)){

Aim Down Sights Script

//Add something to the Component Menu
@script AddComponentMenu ("Weapons/Aim Down Sights")
//For debugging :)
var debug : boolean;
//Positions
var hipPos : Vector3;
var aimPos : Vector3;
//How fast it'll change the position
var smooth : int = 10;
//This is for changing the position smooth
private var goodPos : Vector3;
//Some boolean for lockable aim
private var aiming : boolean;
//Cameras
var MainCam : Camera;
var WeaponCam : Camera;
//FoV Variables
var MCFOVHIP: int = 60;
var MCFOVAIM : int = 40;
var WCFOVHIP : int = 50;
var WCFOVAIM : int = 30;
//For smooth FOV change
private var goodPosMC : int;
private var goodPosWC : int;
var smoothAim : int = 10;
 
function Awake () {
//Let it be hip Position at start! :)
UnAim();
}
 
function Update () {
//Change the position smooth
transform.localPosition =  Vector3.Lerp(transform.localPosition, goodPos, Time.deltaTime * smooth);
if (debug){
Debug.Log("Adjusting Position");
}
//Adjust FoV when we are not aiming
if (!aiming){
ChangeFOVhip();
}
//Adjust FoV when we are aiming
if (aiming){
ChangeFOVaim();
}
//Let the FoV only be changed, if we have a Main Camera, same for Weapon Camera below.
if (MainCam){
if (debug){
Debug.Log("Adjusting FoV (Main Camera)");
}
MainCam.fieldOfView = Mathf.Lerp(MainCam.fieldOfView, goodPosMC, Time.deltaTime * smoothAim);
}
if (WeaponCam){
if (debug){
Debug.Log("Adjusting FoV (Weapon Camera)");
}
WeaponCam.fieldOfView = Mathf.Lerp(WeaponCam.fieldOfView, goodPosWC, Time.deltaTime * smoothAim);
}
//The aiming itself.
if (Input.GetButtonDown("Aim")){
if (!aiming){
Aim();
}
else {
UnAim();
}
}
}
 
function Aim (){
if (debug){
Debug.Log("Aiming");
}
// Let the position be aim Pos
goodPos = aimPos;
aiming = true;
}
 
function UnAim (){
if (debug){
Debug.Log("Un Aiming");
}
goodPos = hipPos;
aiming = false;
}
 
function ChangeFOVhip () {
if (debug){
Debug.Log("Adjusting FoV");
}
//Change the varialbes for smooth aim change
goodPosMC = MCFOVHIP;
goodPosWC = WCFOVHIP;
}
 
function ChangeFOVaim () {
if (debug){
Debug.Log("Adjusting FoV");
}
goodPosMC = MCFOVAIM;
goodPosWC = WCFOVAIM;
}

Bump

For 1: Look into “one shot” for particle systems - basically think of a particle system in the same way you would an animation. It has a start and end, you can loop it or clmap it (play once). So in the matter of particle effects, you’ll probably want to create a new particle effect each time to start and make it a one-shot. You should be able to pool the muzzle effects and set them to the start to optimize memory overhead. That should get you started on that front.