I am creating toggle buttons programmatic in Unity at run time, and I would like to add an event to happen to these toggles.
I want to add to the Unity Event that is triggered when the toggle is clicked, but I can't seem to tie it together properly.
public Toggle myToggle_Prefab;
pulic int numberToggles;
private Toggle[] runtimeToggles;
private void Start()
{
runtimeToggles = new Toggle[numberToggles];
for(int i = 0; i < runtimeToggles.Length; i++)
{
runtimeToggles[i] = Instantiate(togglePrefab);
// ADD TO THE EVENT HERE
runtimeToggles[i].onValueChanged.AddListener(MyMethod);
}
}
private void MyMethod(int index){
// Do something
}
That doesn't work out because it is an integer paramater. The method works with a bool parameter like this:
private void MyMethod(bool arg0)
{
// Do stuff
}
But I need the integer parameter to do what I want to do. Any thoughts?