• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Latex5 · Jun 16, 2017 at 02:50 AM · unity 2dline drawing

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 ();

But the line may cover the sprite object. What should I do?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Latex5 · Jun 20, 2017 at 02:50 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fire emblem like path drawing for a 2D tile based strategy game? 0 Answers

LineRenderer fade out 0 Answers

What is a good in-game drawing solution? 2 Answers

Gizmo.DrawLine rendering problem 1 Answer

2D RPG Opening a Door with Sprites 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges