- Home /
Know Which Button is Clicked
I have eight buttons on screen that I created using 2d Toolkit.
Following image demonstrate my hierarchy window.
Following image demonstrates component that I have added for each button.
Buttons object contain a script called ButtonController in which code for each button exist. In this I want information about which button is clicked by player. For that button I want to do some changes.
Please give some suggestions.
EDIT : Basic working of tk2dButton is, It calls specified method. We don't need to add collider to any object to execute click event.
More detail about my question and I am assuming that I am not using tk2d at all only normal button which has collider attached and sending message to my parent Buttons object.
I have script that contain single method in that and assigned to Buttons object. I want to know which button is clicked. Several buttons attached to Buttons parent object.
I think, now I have given more detail. If you want any further detail then I will provide but I want some nice suggestion for this.
How are you doing 'is clicked by player' - I think gameobject.name should be retrievable via that.
I think you are asking about Raycast. You Raycast and look to see what you hit, and if you hit a button (which you might get via hit.gameobject.name or tag) then you'd pass off to ButtonController.
Take a look at Raycast and see if that's what you are asking about.
First gameobject.name give me name of buttons as name. Second I don't need to use ray cast here because I am using tk2dButton here.
TBH I don't know what you are asking - how can you not know which button is clicked? The screenshots don't tell me anything and I don't use tk2dButton.
Your answer
Follow this Question
Related Questions
Placing button at corner using NGUI 2 Answers
Trigger single collision event 2 Answers
Atlas size based on sprite 0 Answers
Water Fire Effect On 2d Game 1 Answer