laser doesnt work properly

Hey guys i have a few problems the line renderer works fine only it is attached to a weapon on a space ship and my ship moves and the line renderer stays the same i want it to update so when my ship moves the laser(Linerenderer) moves along with it and also with the other end of the line renderer. my second problem is my AplyDamage is not working when my laser hits transform2
question this is a continues beam so it is not a multiple laser it fires one shot at the time and the damage must be aplyed as long as the beam collides

using UnityEngine;
using System.Collections;

public class Laserbeam : MonoBehaviour {

	private LineRenderer lineRenderer;
 	private float counter;
	private float dist;

	public float damage = 10.0f;
	public Transform Weapon;
	public Transform Enemy;


	public float lineDrawSpeed =6f;

	// Use this for initialization
	void Start () 
	{
		lineRenderer = GetComponent<LineRenderer>();
		lineRenderer.SetPosition (0, Weapon.position);
		lineRenderer.SetWidth (.45f, .45f);

		dist = Vector3.Distance(Weapon.position, Enemy.position);
	
	}
	void OnCollisionEnter(Collision col)
	{
		col.gameObject.BroadcastMessage("ApplyDamage", damage); 
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(counter < dist) 
		{
			counter += .1f / lineDrawSpeed;

			float x = Mathf.Lerp(0, dist, counter);

			Vector3 pointA = Weapon.position;
			Vector3 pointB = Enemy.position;

			Vector3 pointAlongLine = x * Vector3.Normalize (pointB - pointA) + pointA;

			lineRenderer.SetPosition(1, pointAlongLine);
		}
	}
}
  1. Make the line renderer a child of the weapon. After you set its original position, it will then just keep that positional relationship with the weapon. I’m assuming that the weapon is a child of your ship and therefore moves with it.
  2. The collision event that you are looking for is OnCollisionStay() to apply the effect over multiple frames. OnCollisiknEnter is only for the first frame that it hits. Anyways, I wasn’t aware that LineRenderer had any physics effects and therefore I don’t believe that it collides with things. I’ve never used it though, so I don’t know. If the problem is that you don’t get collision events at all with the line renderer, Physics.Raycast will be your friend and you will shoot it from the weapon with the same direction and length as the laser and if it hits anything, apply your damage.

Hope that helps. Let me know if you need more assistance

The LineRenderer doesn’t use collision. Seeing as you are making the laser hit the enemy no matter what, at all times, just put your damage in your update function. Make a float called ‘damage’, and increase it every update. in every update, also check to see if it is over a threshold, say, 1. If that is the case, subtract that amount from ‘damage’ and deal that amount to the enemy.
float damage = 0;

void Update()
{
    damage += 5 * time.DeltaTime;
    if (damage >= 1)
    {
        damage -= 1;
        EnemyGameobjectReference.dealDamage(1);
    }
}

As for keeping your line on your weapon, you need to update the position 0 of your LineRenderer, it won’t change otherwise. This is because the variable in the LineRenderer for position of a point on the line isn’t parented to a point, like Gameobjects are.

lineRenderer.SetPoisition(0, Weapon.position);