• 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 VigilantePanda · Dec 22, 2013 at 09:20 PM · texture2ddrawdrawingdrawtexture

Correct way to draw on screen for 2D game

I have rectangular sprites connected to each other to form a rope-like object. When these objects collide with other objects and rotate, gaps appear between the rectangles. I would like these to appear as a contiguous rope with no gaps. In other 2D game engines, I would just draw lines between the necessary points and fill in the center of the shape. I am new to Unity and am wondering what is the appropriate way to do this.

Should I draw on the screen using OnGUI?

Should I create sprites at run-time and fill in the texture programmatically, then rotate/move the sprite as the rope requires? This seems sort of difficult to me initially.

Should I create some kind of custom mesh object where I define the vertices and just fill in the texture programmatically? I'm not even sure how possible this is. Would Graphics.DrawMesh() work for this?

Is Unity maybe not the game engine that I should be using for this type of game that requires a lot of custom drawing on the screen when the drawing is not related to the GUI?

Thanks in advance and let me know if more clarification is needed.

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 robertbu · Dec 22, 2013 at 10:31 PM

If you don't mind spending a bit of money, Vectrosity is a great line drawing package. This is an efficient line drawing solution.

There are a number of other ways to draw lines:

[http://www.everyday3d.com/blog/index.php/2010/03/15/3-ways-to-draw-3d-lines-in-unity3d/] [2]

In addition, you could size and scale quads as lines. The code to do this has been posted a few times in this last year. Here is one post.

http://answers.unity3d.com/questions/444478/instantiating-platforms-between-two-vectors.html

[2]: http://www.everyday3d.com/blog/index.php/2010/03/15/3-ways-to-draw-3d-lines-in-unity3d/

Comment
Add comment · Show 5 · 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 VigilantePanda · Dec 22, 2013 at 11:49 PM 0
Share

Thank you. This information helps. After looking at my question, I don't think I was 100% clear enough with what I wanted to do. This information about drawing just lines will come in handy for other things I want to do.

But, what should I do if I want to outline an arbitrary polygon and fill it in with a solid color? I'm also interested to know if there is a good method for filling the shape in with a non-solid texture, but my immediate concern would just require a solid color.

avatar image robertbu · Dec 23, 2013 at 12:19 AM 0
Share

Typically this problem is solved by creating or manipulating a mesh. If the polygon is convex, then constructing the mesh is not that difficult. If it is not convex, take a look at this link:

http://wiki.unity3d.com/index.php?title=Triangulator

Outlining can either be done by drawing lines, or by shader. Take a look at the Wiki shader archive and search for 'outline':

http://wiki.unity3d.com/index.php?title=Shader_Archive

The what and how of transparency is handled by the shader associated with the material used on the texture. The typical approach uses the $$anonymous$$aterial.color to set the alpha, but if you have many of the same objects using the same (initial) material, then vertex colors may be a better (from a performance standpoint) way to create transparency.

avatar image VigilantePanda · Dec 23, 2013 at 08:57 PM 0
Share

Great. That looks like exactly what I need. I'll give it a try. Thanks!

avatar image shekhar331 · Nov 11, 2014 at 11:19 AM 0
Share

hello, did anyone get an answer for the same .. I want to draw a polygon on a texture and fill it to make it transparent... Can you please help

avatar image nur farazi · Nov 11, 2014 at 11:42 AM 0
Share

nice answer thank you

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Draw a rect from a texture onto another Texture? 0 Answers

Tilt an image by the X axis? 0 Answers

Drawing, Writing on screen. 1 Answer

Drawing in unity UI canvas 2 Answers

Drawing on the Unity UI Image in unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges