- Home /
using specific parts of objects as buttons?
I have a computer monitor in my game and want to use onscreen buttons. At the moment the only way I can think of is to have another object in front of the screen with the same texture and have the button script attached to each of these buttons. What I want is to be able to click directly on the monitor and tell what I clicked on. In the end I want the screen to be able to change or scroll and have the buttons still work. My idea was using a visible texture map for what the player sees and a secondary one that the engine could check if the mouse is over, that way I could use some sort of tracing function to check what color I am over and execute the appropriate button function. It would be nice to be able to change the hover and click texture too (I can do that no problem with the separate object method, but can't scroll the screen or have it just flip to a new screen. Plus it means I have to model each button and it's UV coordinates)
here is what I was thinking, but would need some help getting it running.


as you can see one is just normal buttons, the other has a separate color layout for each one so that leaves a possible 16+ million buttons of any shape. (even using a single alpha map on a non transparent material would still work if it could detect what gray level is used for 256 possible buttons (not that I plan on using anywhere near that many). Please let me know if you can give me some idea how to do this thanks.
Are you setting your monitor up as a GUI? If so you can make the elements directly clickable without having to duplicate them or make it more difficult to handle as a bunch of 3D objects. Otherwise I might just put small nontextured invisible planes with colliders right on top of each button to catch the clicks.
just put box colliders in front of them and draw a ray to test for a hit on each collder
Ok, if it's possible I guess I would update my question to be "How do I use a GUI.button on a GameObject?" adding a plane or collider in front of the button is what I am currently doing, but to make it work like a real monitor that changes screens I would need to make many button objects, code them all and obstantiate and destroy them based on what screen is currently visible. It's doable, but a pain as well as time and processor intensive compared to trying to do a hit test for a specific color on (as example) texture[2] of an object while displaying texture[1] if I apply a texture array to the object. I found hit test for if it's within a defined box on the texture uv map, but that only seems to be for a GUI element (GUILayer.HitTest). I suppose I could write it to use HitTest if I could use it on a texture of a gameobject and combine it to check what screen is currently up, but it doesn't seem to have any use but as a GUI element (as far as the docs say anyway)
Answer by Bunny83 · Sep 15, 2012 at 03:23 PM
So basically you want to do something like this:
http://answers.unity3d.com/questions/289506/how-to-do-a-selectable-map.html
Exactly what I need. The code I was using though didn't work. I apparently didn't realize I needed the raytrace code attached to the camera and the GetPixel code on my monitor screen.
thanks
Your answer
Follow this Question
Related Questions
Problem with texture to reset and re-enter the same texture 0 Answers
arrays / textures help 1 Answer
Can see 3D object through itself 0 Answers
How to make emissive maps glow? 2 Answers
How to change the textures of assigned gameobjects? 1 Answer