I am trying to add an onClick event to a bunch of buttons on screen that I have Instantiated. But the function I am calling needs parameters. When I put the parameters the code doesn’t run but when I don’t it runs but the function doesn’t do what it is supposed to because it doesn’t have the right parameters. Any ideas?
public void PreviewButtonLook(Image previewPart, Sprite previewSprite)
{
previewPart.GetComponent<Image>().sprite = previewSprite;
}
button.GetComponent<Button>().onClick.AddListener(PreviewButtonLook(previewPart, options[i]);