- Home /
line renderer in raycast with one starting point (mouse input) and multiple end point
The problem is on mouse input. the line renderer goes to the first point then from that point going to the last point (if ever i set a position.count=3;) on line renderer
what i want is on mouse input. if raycast hit the same tag on left point and bottom point. line renderer will draw a line from mouse input to the said point (left and bottom) at the same time. not going to the first point first then going to the end point.
can someone please help me with this ?
Answer by LCStark · Oct 04, 2018 at 03:51 PM
From the LineRenderer
documentation:
if you need to draw two or more completely separate lines, you should use multiple GameObjects, each with its own Line Renderer.
Though I guess in your case you could work around it: since you want to draw multiple lines starting from the same point, you could simply add that origin point multiple times, so the line passes through it before going to the next target point:
positions[0] = ray.origin;
positions[1] = point1;
positions[2] = ray.origin;
positions[3] = point2;
...
thankyou! follow up question. how to make the linerenderer disappear after 1 frame ?
You could either disable the LineRenderer
component, or reset its positionCount
field to 0. Doing it in your Update
function before you do the raycasting will hide the renderer at the start of the next frame (assu$$anonymous$$g you don't enable it again with the next raycast). Are you sure you want to do that, though? If you hide it after only 1 frame, it will be barely noticable to the user.
thankyou again! i just did reset the positioncount on update. i want them to notice where the line is going so it'll be fine. thankyou!
Your answer
Follow this Question
Related Questions
Linecast questions. 1 Answer
Unity prediction line renderer 0 Answers
How to make Raycast against LineRenerer 1 Answer
Raycast.distance giving me the wrong number 2 Answers
I have a problem with Layermask Unity2D 0 Answers