The raycast coming from the gameobject and going to the hit point is not going to the position of the mouse. The linerenderer works as it should.
PlayerController Script
if(Input.GetButton("Laser")){
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit)) {
mousePoint = hit.point;
} else {
mousePoint = new Vector3 (emitter.transform.position.x, emitter.transform.position.y, 100f);
print ("no mousepoint");
}
Debug.DrawRay (emitter.transform.position, mousePoint, Color.red);
Physics.Raycast(emitter.transform.position, mousePoint, out targetHit);
if (targetHit.collider != null) {
target = targetHit.collider.gameObject;
print (target.gameObject.name);
}
}//end laser
LineRenderer Script
// Use this for initialization
void Start () {
lineRenderer = GetComponent<LineRenderer> ();
player = GameObject.FindGameObjectWithTag ("Player");
lineRenderer.SetPosition (0, emitter.transform.position);
lineRenderer.SetWidth (.05f, .05f);
}
// Update is called once per frame
void Update () {
Vector3 mousePoint = player.GetComponent<PlayerController> ().mousePoint;
lineRenderer.SetPosition (1, mousePoint);
}
}