- Home /
How can I draw a line with unity2d, and make sure the line not cover the object?
I create a project under unity2D mode, then I use NGUI to create a sprite. What I want to do is that I draw a line when I move my flinger.
I use VectorLine to do it. Part of the code as shown below
Vector2[] linePoints = pathPoints.ToArray ();
mPathLine = new VectorLine("Line", linePoints, myMaterial, 6.8f * mUIRate, LineType.Continuous, Joins.Weld);
mPathLine.Draw ();
Answer by Glurth · Jun 16, 2017 at 06:19 PM
I'm not familiar with the VectorLine class, but I would suspect it is using the GL drawing functions to draw the line. Unfortunately, all GL drawing is done AFTER the scene has been renderered, so everything drawn with GL, just goes on top.
You could use the builtin LineRenderer component, but sadly it does not have an option to draw single-pixel lines: the width of the line is defined in local or world coordinates. (it actually creates a MESH)
Hi Glurth
Thanks for your reply!
Could I think of this effect is not realizable under unity2D.
And I can use LineRenderer component to draw a line, but I need create a project using Unity3D.
Did I get your point?
Your answer
![](https://koobas.hobune.stream/wayback/20220612124254im_/https://answers.unity.com/themes/thub/images/avi.jpg)