- Home /
GetButton and buttonName - what is the buttonName
I want to try out GetButton. Just so happens that I have a button, but I don't know the name, is it "Hole in One!"? If not, how is a name give to a button. Thanks!
GUI.Button (Rect (3,430,105,50), "Hole in One!")
Answer by burnumd · May 05, 2010 at 07:21 PM
Input.GetButton (which is what I believe you're referring to) is used for physical inputs (mice, keyboards, joypads). The "virtual" button described in the docs is the named button assigned to a physical input in the Input Manager. You "read" GUI buttons as Cyclops pointed out in this answer. It is possible, however, to name a GUI button using GUI.SetNextControlName if that's what you're really after, although this approach is primarily used to manage GUI focus and not to make some action happen when a GUI button is pressed.
@burnumd good point, I hadn't thought about the GetButton() function, based on his code sample, but that certainly could be what he meant...
Yeah, I think your answer gets at what the OP is actually trying to do (if I read the question correctly), just thought I'd provide an obscene number of links in case it's not. :)
Dang, but that's a lotta links... the Gui, half a dozen controls, my name, the other answer in the thread... sheesh. :)
Yup, Input.GetButton was what I was getting at. It's cool that you can name a GUI button. Thanks for all the links :) I'll start taking a look.
Answer by Cyclops · May 05, 2010 at 03:55 PM
The way you would use a Button is:
function OnGUI() {
if (GUI.Button (Rect(3, 430, 105, 50), "Hole in One!")) {
print("button pressed");
}
}
It doesn't really have a name, rather you create it and check if it was pressed - then do some code if it was pressed.
Read over the GUI Scripting Guide for more help on how to use the GUI.
Answer by instruct9r · Aug 03, 2012 at 06:32 PM
hi guys. I just found that threat, by searching in google for the buttons names.
I think R Delano, asked you how he can access a button, that was created by script.
For example if we have: GUI.Button(Rect(2, 5, 20, 50), "Example Button");
What will happen if, few lines below i want to make that Button, inactive, so the player can't click it. Can i access the Button's enable property? This way i can put it to 0 or 1...
I found that there is a GUI.enabled class variable, but how i can make it to be exactly for the button, i want it to be? Cuz i might have 10 buttons.... If the buttons have something like a system names, that we can use to reach their properties, etc...
Please do not bump such old threads. The OP here (as well as most other people who posted here) seem to confuse GUI.Button
with Input.GetButton
. Those have absolutely nothing in common. GUI.Button creates a GUI button control inside OnGUI which will be displayed on the screen and can be clicked. Input.GetButton reads the state of a button that is defined in the Input$$anonymous$$anager. GetButton reads the state of a physical button (like a button on the keyboard).
Please, if you have a question, ask a question and do not bump old questions with comments like that.
Your answer
Follow this Question
Related Questions
iPhone Touch Screen? 2 Answers
GUI button fit on both iPhone and iPad 3 Answers
How to make Iphone Menu-Unity 2 Answers
Text is too small while displaying in device 1 Answer
iPhone Home button 2 Answers