x


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!")
more ▼

asked May 05 '10 at 03:46 PM

rd42 gravatar image

rd42
296 30 37 46

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered May 05 '10 at 07:21 PM

burnumd gravatar image

burnumd
3.3k 22 34 71

@burnumd good point, I hadn't thought about the GetButton() function, based on his code sample, but that certainly could be what he meant...

May 05 '10 at 08:07 PM Cyclops

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. :)

May 05 '10 at 08:25 PM burnumd

Dang, but that's a lotta links... the Gui, half a dozen controls, my name, the other answer in the thread... sheesh. :)

May 05 '10 at 08:31 PM Cyclops

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.

May 06 '10 at 12:59 PM rd42
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 05 '10 at 03:55 PM

Cyclops gravatar image

Cyclops
7.1k 33 63 115

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Aug 03 '12 at 06:32 PM

instruct9r gravatar image

instruct9r
76 1 4 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1999
x786
x28

asked: May 05 '10 at 03:46 PM

Seen: 3358 times

Last Updated: Aug 03 '12 at 06:32 PM