I’m trying to make my character shoot a laser beam or ray similar to this video: Diablo 3 - WIZARD skills: disintegrate - YouTube I can’t even get the laser to show up. Here’s what I have. I don’t care about what it looks like or colliding with anything I just want the laser to originate at my character and continue to the point where my mouse is clicking.
using UnityEngine;
using System.Collections;
public class PlayerShoot : MonoBehaviour {
public GameObject laser;
// Update is called once per frame
void Update () {
if(Input.GetMouseButton(0)){
Plane zeroPlane = new Plane(Vector3.up, Vector3.zero);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float distance;
if(zeroPlane.Raycast(ray, out distance)){
Vector3 outputPosition = ray.origin + ray.direction * distance;
(laser.GetComponent(LineRenderer)).SetPosition(0, this.transform.position);
(laser.GetComponent(LineRenderer)).SetPosition(1, outputPosition);
Debug.Log("Position: " + outputPosition);
Debug.DrawLine(transform.position, outputPosition, Color.white);
}
}
}
}