How to draw a line?

This more a “yes or no” question than an actual question.
I’m working on a game where the player can select elements. When he clicks on elements I draw a line between the previous selection and a the new one. I’m currently using the Debug.Drawline function to display the link between chosen elements but I need a final method.

My idea is to import a quad from Blender (to avoid using Unity planes which are full of vertex) scale it, rotate it, and display it always facing the camera.

My question: Is it the good technique to display lines or is there other techniques?

I have a similar type of game, and LineRenderer works pretty well. There's no significant problems with using LineRenderer as long as you don't have hundreds or thousands of lines.

Well, here's my standard link: [Vectrosity][1]. [1]: http://www.starscenesoftware.com/vectrosity.html

@Eric5h5: You and your paid solutions. I think a lot of us happen to be Scrooges. Well, I'd like to think that.

That's why I don't post them as answers. I've written quite a lot of free scripts on the wiki which I also link to. Fortunately many people are not Scrooges.

the price is too low, the only problem with most Asset store products

1 Answer

1

You can use line renders, which allow you to define a start and end point, as well as width. This is generally more simple than using a quad, but I think it may be less efficient.

-AJ

It is less efficient because it requires the space for the GameObject and Component to hold it.

Unless you had Unity Pro, in which case it is drawn directly without anything to hold it.

@Mizuho @ArielJohnson I've tried Line renderer technique... but it seem to not always facing camera (example where I expect to have a square drawn: http://delta.riskle.com/~larles/unityline.JPG ) Is there something to know with LineRenderer while using an orthographic camera?

@lvictorino: You can't have more than two points on the line for the line bends. There are only two ways to do it: 1. Cross over the same line FOUR times. 2. Use two LineRenderers, each belonging to their own GameObject.

@Mizuho I'm sorry but I don't understand your solution. How can I get a square with only two LineRenderers ?