So I am currently trying to make it so that instead of having to do this
GameObject B = GameObject.Find ("Arrow Left");
previousPageButton = B.GetComponent<Button> ();
previousPageButton.onClick.AddListener (() => { PreviousPageButton();});
for each of the buttons, make a method like this
void ButtonFiller(string Name, MyDelegate Function, Button ButtonName){
GameObject Temp = GameObject.Find (Name);
ButtonName = Temp.GetComponent<Button> ();
ButtonName.onClick.AddListener(() => {Function();});
}
and call it like here
ButtonFiller ("Arrow Left", PreviousPageButton, previousPageButton);
This works fine but I also have buttons like these
GameObject B = GameObject.Find ("Back");
backButton = B.GetComponent<Button> ();
backButton.onClick.AddListener(() => { BackButton(infoMenu);})
Where the method I call with the button has an argument.
How do I make a method like the ButtonFiller that also works for Buttons that call a method with an argument. I know i will have to use a delegate which takes an argument but don’t know how to do that when using it as an argument for another method.
It will probably be a simple answer but I don’t seem to understand this.