- Home /
Question by
AwesomeFaceHD · Aug 22, 2014 at 03:52 PM ·
c#vector3linerenderer
Make LineRenderer from one Vector3 to another Vector3?
I made a graphing calculator and I want to connect the points that are spawned with a LineRenderer.
I have this function that I want call the line with:
void DrawLine(Vector3 a, Vector3 b) {
// Code to draw line from a to b
}
I've read a lot about it, but I'm still really confused as to how to do it.
Comment
Best Answer
Answer by Cherno · Aug 22, 2014 at 04:10 PM
LineRenderer lr = GetComponent<LineRenderer>();
Color startColor = Color.green;
Color endcolor = Color.red;
float startLineWidth = 0.5f;
float endLineWidth = 2.0f;
Vector3 pos1;
Vector3 pos2;
lr.enabled = true;
lr.SetVertexCount(2);
lr.SetPosition(0, pos1);
lr.SetPosition(1, pos2);
lr.SetWidth(startLineWidth, endLineWidth );
lr.SetColors(startColor, endcolor );
Thanks. It took a little messing with to get how I need it, but it works perfectly now.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161246im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to find a point(vector2) between two points(Vector2) of a line (line renderer) 2 Answers
slowly rotate a object *need quick fix* 0 Answers
Linerenderer doesn't match my ray. 1 Answer
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer