How do I access the clicked radio button from the callback?

I have a radio button group, and I’m trying to find a way to know which button has been pressed, within the callback. I’m quite stunned I can’t find a way to do that, and searching google only provided useless trash.

Currently I’m forced to do this horrible horrible thing:

private void RadioLapsX ( int laps ) {
	Debug.Log("RadioLapsX: "+laps);
	ActiveDirector.multi.matchLaps=laps;
}
public void RadioLaps1 ( bool active ) {
	if (!active) return;
	RadioLapsX(1);
}
public void RadioLaps3 ( bool active ) {
	if (!active) return;
	RadioLapsX(3);
}
public void RadioLaps6 ( bool active ) {
	if (!active) return;
	RadioLapsX(6);
}
public void RadioLaps9 ( bool active ) {
	if (!active) return;
	RadioLapsX(9);
}

Is there a sane way to do that?

Having to call a different function from every button seems incredible to me.

I think UICheckbox.current is what you’re looking for. It refers to the current UICheckbox being set. (See void Set (bool state) inside UICheckbox to know exactly when current gets set)

Another way (I don’t know why would you wanna do it like that, but anyway), since they’re radioboxes which means only one of them will be set/checked at a time, you could get the state of your checkboxs, the one that’s checked is your guy. To do that just to subscribe to the onStateChange delegate, and add your handler:

(This is gonna be inside a script that you will add to your checkbox object, where the UICheckbox is attached)

void Start()
{
	var cb = GetComponent<UICheckbox>();
	cb.onStateChange += OnStateChange;
}

void OnStateChange(bool state)
{
	if (state)
	   Debug.Log("I'm your guy");
}

You could also specify an eventReciever and a function name (by default it’s OnActivate)

void OnActiviate()
{
   // this gets called whenever the state changes
}

That’s not very useful, as you don’t know what the new state is.