Prefab Instantiation

I am currently working on a script to control a laser beam, that on hit with certain objects emits a particle effect at the point of collision.

However the issue is I am unable to figure out how to only Instantiate a single emitter at a time so as not to have too many draw calls.

I have tried several different methods, including WaitForSeconds(), InvokeRepeating() and using bools but to no avail.

Here is the code as it stands, it Instatiates a single particle emitter every frame at the moment. I am probably being an idiot and the solution is staring me in the face but anyway you’ll find the code below.

public class LaserWall : MonoBehaviour
{	
	RaycastHit hitCheck;
	public float laserLength = 20.0f;
	public GameObject hitEffect;
	public GameObject spaceShip;
	
	void Start ()
	{
		GetComponent<LineRenderer> ().SetPosition (1, Vector3.forward * laserLength);
	}
	
	void FixedUpdate ()
	{	
		LaserCollisionCheck();		
	}
	
	void LaserCollisionCheck ()
	{
		if (Physics.Raycast (transform.position, -Vector3.up, out hitCheck, laserLength) && GetComponent<LineRenderer> ().enabled == true) {	
			Debug.Log ("Hit");
			if (hitCheck.collider.name == "space_ship") {
				Instantiate (hitEffect, hitCheck.point, Quaternion.identity);
				GetComponent<LineRenderer> ().SetPosition (1, Vector3.forward * hitCheck.distance);	
				//spaceShip.GetComponent<SpaceshipController>().Explode();			
			}
			if (hitCheck.collider.name == "laser_wall") {
				Instantiate (hitEffect, hitCheck.point, Quaternion.identity);
				GetComponent<LineRenderer> ().SetPosition (1, Vector3.forward * laserLength);
			}
		}
	}	
}

Thanks in advance to anyone that can help, just to clarify I am trying to reduce the number of particle emitters being created to around 1 per second.

~ byteCrunch

If you want to create a kind of “laser cut” effect, where the particles are emitted while the laser is hitting something, it would be better to place the particle emitter in the scene with emit = false (you may child it to the laser weapon), and when the laser hits something, set emit to true. There are also other wise things to do, like caching the line renderer in a variable and use Update instead of FixedUpdate:

    ...
    public ParticleEmitter hitEffect; // drag the particle here
    public GameObject spaceShip;
    LineRenderer lineRendr; // line renderer reference

    void Start ()
    {
       lineRendr = GetComponent< LineRenderer>(); // cache the line renderer
       lineRendr.SetPosition (1, Vector3.forward * laserLength);
    }

    void Update () // use Update instead of FixedUpdate
    {  
       LaserCollisionCheck();       
    }

    void LaserCollisionCheck ()
    {
       if (Physics.Raycast (transform.position, -Vector3.up, out hitCheck, laserLength) && lineRendr.enabled) {  
         Debug.Log ("Hit");
         if (hitCheck.collider.name == "space_ship") {
           hitEffect.transform.position = hitCheck.point;
           hitEffect.emit = true;
           lineRendr.SetPosition (1, Vector3.forward * hitCheck.distance); 
           //spaceShip.GetComponent().Explode();       
         }
         else
         if (hitCheck.collider.name == "laser_wall") {
            hitEffect.transform.position = hitCheck.point;
            hitEffect.emit = true;
            lineRendr.SetPosition (1, Vector3.forward * laserLength);
         }
         else { // nothing hit, set effect to false:
            hitEffect.emit = false;
         }
       }
    }