- Home /
Make a GUI button automatically clicked down
Hi, I was wondering how I would be able to make a button automatically down without the player clicking and holding it. Thank you.
Do you mean visually or functionally as well? That is, do you want a button that displays as constantly pressed after the user clicked it once, but executes only once, or are you asking about how to move the actual mouse pointer and invoke a button click in code?
I just want it to display as constantly pressed without executing anything until the player presses a key.
Answer by CHPedersen · Nov 13, 2011 at 12:39 AM
You can't make the default button exhibit that behavior, but you can fake it by playing around with the styles. :)
At its core, there is no magic about the appearance of a pressed button, it's just another texture. All buttons have textures for pressed and normal states. So, when you make your GUI.Button or GUILayout.Button, don't draw it with the default GUIStyle for a button - draw it with the GUIStyle for a textured label instead, and then replace the texture on the label manually each time the user clicks the button.
You can download the default Unity skin in this forum post:
http://forum.unity3d.com/threads/7173-Official-skins?p=84065#post84065
The button textures for pressed and normal states are in that package. Figure out which one is for pressed, and which one is for normal, and then just swap them on the label-style you draw the button with. That should give you the desired behavior.
Your answer
Follow this Question
Related Questions
GUI.Button's status react to keyboard event? 0 Answers
When mobile keyboard is active, button clicks are not responding 0 Answers
how to use Gui.Buttons and keyboard ? 1 Answer
Click a button when keyboard is open (Android) 0 Answers
Is it possible to link a button on my keyboard to disable fog in-game? 1 Answer