Selection box

How would I create a selection box around an object at runtime like the ones that appear in the editor when you click and object? :smile:

The editor does a wireframe render with back face culling when an object is selected. You could access the mesh via the MeshFilter.

If you have Unity Pro (not iPhone or iPhone advanced) you could then use the GL class to draw the wireframe shape as you see fit.

This all depends on the performance you need and it may be better to go with a cheaper effect. There are plenty of ways to highlight the shape of your geometry. Again, it depends on the type of project you are working on, but some kind of overlay or material effect may be an idea. It’s just a trade-off against performance.

Alternatively you could render the bounding volume of the mesh (also available in the Mesh), which would highlight your object but maybe not “shrink wrap” in the way you intended.

I am working with meshfilters and what I’m trying to do is highlight all of the lines so you can view the vertices.

Also I do not have Unity Pro. $1200 is ALOT! :wink:

Kinda old post but I still need this info…

So is what you’re after basically a wireframe superimposed on the object as it’s normally rendered? (Originally you mentioned a selection box, but later you said you want to highlight all of the lines, by which I assume you mean the edges of the mesh triangles.)

I just want a basic hightlight to show what object is selected, right now I have the object turn green when you select it but this isn’t going to work anymore because I made RGB sliders to recolor the selected object.

Check the shaders forum.

I already said I don’t have Unity Pro. :?

Shaders are supported in ALL versions of unity.

Iphone, Android, and Wii only support FixedFunction shaders, but if you aren’t paying for any package, I doubt you are deploying to any of these platforms.

Really? I thought they weren’t supported. :sweat_smile:

How could I use a shader for this anyway?

Shaders are a low-level scripting language that are offloaded to the graphics card. When an object with an attached shader is offloaded onto the graphics card, the shader runs through each pixel, vertex, face, etc. And applies a modifier to them. This allows direct control over the shape of an object, the color of an object, or just about anything you could possibly imagine.

To apply a shader to an object, simply create a new shader, then create a new material. Edit the code of your new shader, set the material’s shader to the new shader (it’s in the top pulldown menu in the inspector), and you should be fine. Like I said, check the shader forums for some good outline shader code.

I got a shader but I have no clue how I insert it when I click on an object, I tried addcomponent but it said it doesn’t exist.

Create a new MATERIAL asset, and change the shader to the new shader you just created.

Next, edit a MeshRenderer component’s material value to be the material you set up.