- Home /
How do you create an effect where a game object button looks like it's being pressed?
I'm trying to create an effect where the buttons I've created look like they're being pressed when the user clicks on them. I've created buttons using a plane with an image material on it, and then creating a raycast.hit when someone presses the button (I purposefully didn't use the Unity GUI system for performance reasons).
What would be the best way to make the buttons brighten up or look like they're being pressed when they're clicked? I was originally going to just make different versions of each button image in illustrator, one for pressed and one for normal, but I felt like they're might be a more efficient way to change them all in the same way in response to a click.
Answer by Dracorat · Apr 16, 2013 at 05:33 PM
You really should create separate images and just swap them out rather than try to hack camera effects in.
In general, the effect that buttons use for being pressed is either:
Beveled buttons: top left corner highlight for not pressed is swapped to bottom right corner which gives the visual effect of being pressed when compared to it's neighbors.
Flat buttons: Either have a drop shadow in the unpressed state that is removed and the button is moved down and right -- or -- an inner shadow is added to the button as it's pressed to make it look like it went through the page (with no drop shadows).
It's best if you recreated these effects in Illustrator and just used the texture accordingly. If you try to hack it in, it's going to look like it.
If you're going with full 3D objects as buttons, you could just move it in and down and right and probably get a good effect - but only if they're full 3D objects.
Answer by Glister · Apr 16, 2013 at 03:22 PM
I think your on to the right idea with having two separate images if you want the button to appear depressed. I don't believe there is an easy way to make the buttons appear to be depressed when the user clicks it without a second image.
As far as having the button light up you could add a lighting affect to the button like glow or a spotlight that you could turn on and off when the user clicks the button. This wouldn't change the image of the button but would give an effect that was visible when the button was clicked.
How would I add a lighting affect to the button like glow or a spotlight? I tried changing the shader, but all the shaders I tried make the button look very strange, with fuzzy edges or just too dark or too light.
The way I would add glow is to use a point light and place it on the object turn on the halo effect and change the settings till you get a nice effect that you like. Then just script the light to turn on and off with the clicks. You can find a some code Here that will help with switching the light on.
Note: $$anonymous$$ake sure you add code to turn the light off On$$anonymous$$ouseUp light.enabled = false; (This will make more sense if you look at the code linked above.)
Your answer

Follow this Question
Related Questions
Creating a component from a button click 1 Answer
Change GUI.Button Texture on runtime 1 Answer
gui.button not display text and texture 2 Answers
GUI Texture on Button Swap 3 Answers
Change the texture of a GUI BUTTON 1 Answer