0

I have a system that creates buttons based on the files in a directory. I need to call a function in a script based on what a child object of the button's Text component text property reads. Basically, i need to modify each button to call a function with a specific paramter. How would I do this?

Brady W
  • 271
  • 10
  • 23

1 Answers1

1

I think you need to check this : Event trigger Script

https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html

The Event Trigger Script allow you to call a method of child component on trigger (click, mouseover..).

(check this : http://answers.unity3d.com/questions/974622/unity-502f1-ui-button-onclick-function.html)

EDIT :

If you do not know in advance which method is to be assigned: you can use System.Reflection to retrieve the associated method.

string name = "BtnAction";
MethodInfo m = t.GetMethod(name);

I hope this will help you :

For each button, attach the components "Event Trigger" and your script with all your methods.

Then use reflection to get the associated method.

Finally, set the Event Trigger component using :

button.onClick.AddListener (FunctionToCall);