- Home /
Question by
nictm · Aug 07, 2018 at 08:53 PM ·
linerendererreflect
Reflecting a Line Renderer on collision
Hello All,
I'm trying to figure out how to reflect a line renderer on hitting on object. In the script, when I push "A" I have the line enabled, but when it hits my object with the tag "Def", it is not reflecting. Not sure what to put at the ???? or maybe something else needs to be fixed in the script. Any help would be awesome, Thanks!
This is the script so far:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LaserLeft : MonoBehaviour {
LineRenderer line;
void Start ()
{
line = gameObject.GetComponent<LineRenderer> ();
line.enabled = false;
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.A))
{
line.enabled = true;
Ray ray = new Ray (transform.position, -transform.right);
RaycastHit hit;
line.SetPosition (0, ray.origin);
if (Physics.Raycast (ray, out hit, 200))
{
line.SetPosition (1, hit.point);
}
else
{
line.SetPosition (1, ray.GetPoint (200));
}
if (hit.collider.tag == "Def")
?????
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612172410im_/https://answers.unity.com/themes/thub/images/avi.jpg)