Unity - Drawing Lines
Jump to navigation
Jump to 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:
- Use Line Renderer component - easiest to use (go Component > Misc > Line Renderer, then list points), but also the least efficient as constantly re-computes.
- Use Mesh class - doesn't require game object, generated on the fly and much faster.
- 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.
- Articles and code:
- Everyday3D - 3 ways to draw 3D lines in Unity 3D - a brilliant article by Bartek Drozdz, which provided much inspiration for my own article.
- Creating the visual for the line of sight / vision cone / field of view - a short article explaining methods to make a dotted line representing line of sight.
- Unity API: