Unity - Drawing Lines

From NoskeWiki
Jump to: navigation, search

About

NOTE: This page is a daughter page of: Unity


Unity3D is a multi-platform 3D game engine. This page gives some links specific for dealing with Textures in Unity.


Rendering 3D Lines in Unity

For drawing lines in Unity there are three main options:

  1. Use Line Renderer component - easiest to use (go Component > Misc > Line Renderer, then list points), but also the least efficient as constantly re-computes.
  2. Use Mesh class - doesn't require game object, generated on the fly and much faster.
  3. Use direct drawing with the GL class - fastest still, but only available with Unity Pro.

There's fantastic article explaining these three options here, which provides demos and code for each. For option #2 I've provided a useful snippet of code under Unity - Mesh.


Rendering 2D Lines in Unity

It appears there's no easy work around for drawing lines over the GUI. Instead, what many have done is render a Texture in the desired color, then use a combination of GUIUtility.RotateAroundPivot() and GUI.DrawTexture to achieve a line going between any two arbitrary points. The code for this is at: unifycommunity - DrawLine.


Links

  • Vectorisity - a commercial package sold for quite cheap (~$10-25) which provides some nice classes for drawing lines without needing Unity Pro.