- Home /
Programatically set a button
I'm trying to set up a dialog box when the user is deleting an entry in the database so that they choose yes to delete or no to not delete. The delete script in on a prefab, so instead of creating multiple buttons stacked on top and enabling them, is there a more generic way to do it? The no would just close the canvas.
$$anonymous$$ake a way to select the entry that should be deleted, then your delete button deletes the selected entry?
Yes, but when the dialog comes up, it needs to know what to do.
What do you mean by "The delete script in on a prefab"? How is the prefab being used?
The application is pulling data from a mysql database via the webform and displaying it via an instantiated prefab. Normally I would put all functions on a singleton script, which I have. However, for some unknown reason the delete function did not work when I tried to access it via the singleton, so I had to move it to the prefab. Does that help Trey?
Answer by Tohron · May 01, 2019 at 03:34 AM
Not sure if this is what you need, but you add listeners to buttons using the format myButton.onClick.AddListener(delegate { MyActionFunction(myArgument1); });
Arguments are optional. Make sure if you are providing a constant argument that you pass in a variable which isn't changed later.