- Home /
How can I make certain parts of my object selectable?
I have one mesh object. I want the user to be able to hover over a part of the object and then the object will show a prominent color change allowing the user to select or click the region that will eventually have an event listener that goes into another scene or action.
Now I'm just curious as to how I can make certain parts of my ONE object mesh selectable/highlightable?
I can't find any information on this online. Does this mean that I have to chop up my object in various pieces for the user to select a certain region or is there a way to highlight the part of the object without chopping it up?
Also, it seems like one possible way is to add texture overlap on the mesh but I'm not sure if that's really what I need?
The biggest problem is I want the region that's highlightable to be really thin because I want to make it look like a cut in the object was selected.
Answer by robertbu · Dec 12, 2013 at 03:23 PM
One solution is to create a second texture for the object. For each area you want to be able to select, give it a specific color. That is by using different colors, you have the ability to specify different events for different hit areas. Then you can use the the textureCoord from the RaycastHit structure used in the Raycast() to get the color. If the color is a close match to a specified color, then you have a hit for that color and can generate the event.
I want to try the TextureCoord script before I manipulate it and it's not working for me. I added the js portion of the provided script to my main camera and nothing happens to my object.
I made sure I attached a mesh collider and a mesh renderer to my object.
I just tested the sample script, and it worked fine. $$anonymous$$ake sure your texture is RGBA32, and that you have it read/write enabled. Note for what I outline above, you don't need a visible texture, nor does the texture need to be the same size. It just needs to have the same aspect ratio. You can use Texture2D.GetPixelBilinear().
How do I make sure my texture is RGBA32 and read/write enabled? I'm a beginner
Select your texture in the Project pane
In the Inspector pane, set 'Texture Type' to Advanced
Turn on 'Read/Write Enabled'
Turn off Generate $$anonymous$$ip $$anonymous$$aps
In 'Format' select RGBA 32-bit
Other settings will work, but this is a place to start.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124016im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# Preserving GameObjects' Previous Meshes 1 Answer
highlight objects, i really need help pls 0 Answers
Autoscale Shader with multiple random texture selection. 0 Answers
Problem with non convex mesh colliders 4 Answers