#find button in list based on selected button
1 messages · Page 1 of 1 (latest)
That's clever, it's been so much time since these were disabled, I don't remember to use them lmao
Honestly I hated the addition of threads, but only because I was in servers who didn't need them at all
but for stuff like this it's good
Anyways
So, any other errors? You should have one I think
None
So you edited EmployeeButtonClicked so it takes a param of type Button? Good
So an employee object is a prefab, generated like:
Employee1:
|--- Name (Text)
|--- Design (Sprite)
|--- B_SelectEmployee (Button)
the B_SelectEmployee is what we're dealing with
Yup that's what I deduced from the original code you posted
all employees are gathered into a list called NotHired
all buttons are gathered into a list called EmployeeButtons
which are generated right after another, so they're 1 - 1
so if I can get the index of the selected button in employeebuttons, I'll get the one in NotHired too
you probably already figured that out, but that's the goal
Okay, now show the EmployeeButtonClicked handler method, the magic will happen there
public void EmployeeButtonClicked(Button button)
{
}```
nothing atm
I have a selectedEmployee int which will be the returned index
Okay good. So you've got the button that raised the event as a parameter, the button list as a class field, and the IndexOf method. You're all set
RIght
Actually
Each button has a selected attribute right
we could do
for i = 0; i < EmployeeButtons.Count' i++
if EmployeeButtons[i].isSelected
return i
You don't need it. You have a reference to the clicked button (your parameter), and the button list.
Debug.Log(EmployeeButtons.IndexOf(button)); should print out the index of the sender in the console.
It's a shame that the overall Unity event system doesn't include that "sender pattern", and you have to do it yourself
Seems right to me
Okay, so if there is no more questions nor anything else to discuss, I'll let you archive this thread to clean up