Greetings, I am having an issue with add a onclick listener to a dynamic button. Whatever I try it doesn't appear to be adding as viewed from the editor. Here is what I have: Code (CSharp): private Button getButton(int i) { Button buttonPanel = (Button)Instantiate(buttonPF, transform.position, transform.rotation); buttonPanel.name = ("Button"); Image panelImage = buttonPanel.image; panelImage.sprite = GameConstants.basicBackground; panelImage.type = Image.Type.Sliced; panelImage.color = new Color(0.4f, 0.4f, 0.4f, 1.0f); buttonPanel.onClick.RemoveAllListeners(); buttonPanel.onClick.AddListener(delegate { doThing(i); }); GameObject buttonLabel = new GameObject("Button Text"); Text buttonText = buttonLabel.AddComponent<Text>(); buttonLabel.transform.SetParent(buttonPanel.transform); buttonText.font = GameConstants.defaultFont; buttonText.alignment = TextAnchor.MiddleCenter; buttonText.fontSize = 20; buttonText.text = getButtonText(i); buttonText.rectTransform.sizeDelta = new Vector2((sideBarWidth / 4) - 10.0f, 35.0f); buttonText.rectTransform.localPosition = new Vector2(0.0f,0.0f); panelImage.rectTransform.sizeDelta = new Vector2((sideBarWidth / 4) - 00.0f, 40.0f); if (i == 3) { panelImage.color = new Color(0.8f, 0.0f, 0.0f, 1.0f); ; } return buttonPanel; } public void doThing(int i) { Debug.Log("Hit!"); } Thanks for your time.
Is there anyway to check if they are added correctly? My buttons still don't do anything and I was thinking that maybe I added them wrong but maybe my button just isn't working? Thanks!