Trying to make a visible laser weapon in unity (using raycast and linerenderer) but not sure how

Viewed 14

So I am trying to make a hitscan laser weapon, from what I seen the weapon it self seems to be working. But I don't know how to make the ray visiable, I tried understanding line renderer but frankly I have no idea what I'm doing. Any tips?(This is the raycast code)


using System.Collections.Generic;

using UnityEngine;



public class Weapon : MonoBehaviour

{

private float damage = 10;



// Update is called once per frame

void Update()

{

if (Input.GetKeyDown("k"))

{

Shoot();

}



}



void Shoot()

{

RaycastHit hit;

if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))

{

Health target = hit.collider.GetComponent<Health>();



if (target != null)

{

target.TakeDamage(damage);

}

}



}

}``` 
1 Answers

Maybe you could instantiate a laser sprite heading in the direction of the raycast going really fast

Related