I have this function here to duplicate a UIPanel(Prefab) and its components. It duplicates, then succesfully assigns a objectname and enable/disable the Interactable setting of the button component. But the part where it sets the ''OnClick'' on my button does not work. I dont understand as I can play with other options of this button component...
Yes the function Click exists. Yes I included my using using System.Collections.Generic; using UnityEngine.UI;
Any Help? Thanks.
public Text Title; public Button Btn; public void CreateEventSquares(string keyval, string valueval) { string Event = (keyval); string Link = (valueval); Debug.Log("Event :" + Event + "Link is :" + Link); NewPanel = Instantiate(Event0); NewPanel.transform.SetParent(EventPanel.transform); NewPanel.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); NewPanel.name = keyval; //Sets the button action to trigger Click function (Not Working) Btn = NewPanel.GetComponent<Button>(); Btn.onClick.AddListener(Click); Btn.interactable = false; //Sets the title same as keyval (This Works) Title = NewPanel.GetComponentInChildren<Text>(); Title.text = keyval; }
Click
public void Click() { //do This }
https://stackoverflow.com/questions/66996032/any-clues-on-this-unity-code-not-working April 08, 2021 at 09:05AM
没有评论:
发表评论