I’m making a top down 2d shooter in which there is a beam weapon I found a tutorial and followed it however the output isn’t quite what I was hoping for.
the beam is supposed to shoot at the mouse position however here it is shooting at the origin point (0,0)
how do I make the beam shoot at the mouse?
here is the code:
using UnityEngine;
using System.Collections;
public class beamWeapon : weaponObject {
RaycastHit hit;
float range = 100.0f;
LineRenderer line;
public Material lineMat;
Ray ray;
void Awake()
{
line = gameObject.GetComponent<LineRenderer> ();
line.SetVertexCount (2);
line.material = lineMat;
line.SetWidth (0.1f, 0.25f);
}
void Update()
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
}
public override void FireWeapon()
{
Physics.Raycast (ray, out hit, range);
line.enabled = true;
line.SetPosition(0, transform.position);
line.SetPosition(1, hit.point + hit.normal);
}
public override void stopFiring ()
{
line.enabled = false;
}
}
