- Home /
Drawing an outline around object
Hey, I'm using an orthographic camera from a top down view and when an object is selected I would like to draw an outline around it that scales to the size of the objects collider. This is probably simple enough to do with a mesh, but the problem I see happening is the width of the outline changing as I scale the mesh, which I don't want. What's the best way to get around this?
EDIT: By outline I mean just a rectangular outline with the width and length of the objects bounding box collider
what are the objects in the game?
are the objects cats, spaceships, or square images? or rectangular?
secondly what "are" the objects? are they 3D models, 2D sprites, colliders, or what?
Sorry for the lack of information, the objects can be a range of things, turrets, fences etc. Each will have a 'bounds' collider which will be used for making sure that these objects are not placed intersecting others. The outline should be drawn with the width and length of this bounding box collider. EDIT: By outline I just mean a rectangle around it, sorry I didn't realise I hadn't said that in my first post.
Answer by Fattie · Dec 16, 2012 at 11:58 AM
OK thanks for clarifying that you want to draw four straight lines, as seen from the camera, in the shape of a box, around some objects.
There's basically two ways to draw lines un Unity.
You can use the LineRenderer which is free with Unity. Simply read the doco, it is very easy to use.
Or you can grab Vectrosity on the asset store for two dollars, which pretty much everyone uses for drawing lines, glowing lines, and the like.
There is a third remarkably easy way:
right now in unity in the editor, just "make" a "line". So, make it exactly 10 cm wide, and 1 meter long. Very simply make a "plane" using a silly unity primitive, and stretch it so it is as I describe.
it might be easuer for you to make a horizontal one of those, and also a vertical one
name those objects say MeterLineH and MeterLineV. (note that this will now have a scale of "1" both ways)
carefully make a little system where you supply a length (say "2.3 m"). the system takes your original MeterLineV and simply scales it, in this case simply to 2.3 on the vertical length. Do the same thing for horizontal
note that you can color the originals (from point 1) any way you want, etc
As you can see, you can now, with one line of code, make horizontal or vertical lines, any length you want, and always a fixed 10cm in width. Voila.
just carefully write a routine that makes a BOX from four of those
So really that's how you do it. Note that, FWIW, there's no reason not to use a "cube" in step 1 (stretch it out). Or you could "properly"
Let me finally say - did uou look at Unity's (annoying and crappy) GUI system?
Note that it has stupid features like "box" and so on ...
http://docs.unity3d.com/Documentation/ScriptReference/GUI.html
Be aware it will take you 10x, or 40x longer to use their "GUI" system, than simply do the 7 steps I mention above!
Finally !!!
Funnily enough I had exactly this problem once. Let me dfraw your attention to a great little product on the Asset Store (it's only five bucks!) called "Dynamic Circles" - everyone should have it, it;s so good
notice in this question (similar to yours here), I came to that conclusion
http://answers.unity3d.com/questions/238526/easiest-way-to-make-a-kind-of-glowing-indicator-ar.html
Hope all of this helps in some way! So your solutions are
LineRenderer of Unity, a bit clunky for this
learn Vectrosity, the go to solution for glowing lines etc
surprisingly, just make essentially stretched planes, to make tidy squared-off lines
note the natty "Dynamic Circles" asset which is neat (since it's only a few bucks, just grab it without hesitation as it's interesting)
Hope this helps! Cheers!
Thanks for the great info Fattie, that third method looks pretty good. Also for the link to dynamic circles, probably going to have to pick that up, it looks awesome!
"Let me finally say - did uou look at Unity's (annoying and crappy) GUI system?" Yes I did. It was annoying and crappy. Pretty much just waiting for the new system to come out before I do much work on my game's gui (wish I could find a release date somewhere lol). But I should at least be able to get this working for now so thank you very much!
LOL on the gui !
really i think it's better just to make one's own, I use 2DToolkit everywhere, it's pretty essential in Unity
well cheers
Your answer

Follow this Question
Related Questions
Combining two Outline Shaders 1 Answer
How to make a outline shader with custom attributes 0 Answers
Using a texture map to determine the colors of a toon outline? 0 Answers
Mixed Standard and outline shader, outline not showing at some distances 0 Answers
It there Outline for TileMap tile? 1 Answer