Best way to place a Line Renderer into scene...

Hi there!

So, I’m trying to make an energy beam, using a Line Renderer, that’s fired every time the player presses “mouse 0”. However, I need to know how can I spawn the line renderer every time the player presses the button, and also, set it’s positions (element 0 and 1) in the player ship and the target object, using Unityscript…

So, any idea?

Thanks in advance.

JPB18

Found a solution by myself, and here’s the function I ended up creating:

function fire_phaser_player() {

		if(Input.GetAxis("Fire1"))
		{
			if (target != null)
			{
				if(weapon1.isBeam == true && weapon1.isPresent == true)
					{
						var line_rend : LineRenderer;
						var script : playerShip = target.GetComponent(playerShip);
						if(isBeam == false)
						{
							//render the beam
							beam = Instantiate(weapon1.beam);
							line_rend = beam.GetComponent(LineRenderer);
							line_rend.SetPosition(0, transform.position);
							line_rend.SetPosition(1, target.position);
							isBeam = true;
							
							//do damage
							
							if (script.isRedAlert == true && script.shields > 0)
							{
								script.shields -= weapon1.damage * weapon1.shieldMulti * Time.deltaTime;
							
							}
							else
							{
								script.health -= weapon1.damage * weapon1.hullMulti * Time.deltaTime;
							}
							
							
						}
						else
						{
							//orient the beam
							line_rend = beam.GetComponent(LineRenderer);
							line_rend.SetPosition(0, transform.position);
							line_rend.SetPosition(1, target.position);
							//do damage
							
							if (script.isRedAlert == true && script.shields > 0)
							{
								script.shields -= weapon1.damage * weapon1.shieldMulti * Time.deltaTime;
							
							}
							else
							{
								script.health -= weapon1.damage * weapon1.hullMulti * Time.deltaTime;
							}
						
						}
					}

			}
			
		
		
		}
		else
		{
			if(weapon1.isBeam == true && weapon1.isPresent == true)
			{
				isBeam = false;
				Destroy(beam);
				beam = null;
			}
		}
	


}

weapon1 is a class I created to hold the characteristics of beam weapons, beam is a var that holds the GameObject of the beam that’s currently being fired, isBeam is a boolean var that’s used to check if the beam is being fired and target is the current target of the ship.