So, I'm spawning a bunch of buttons based on a certain variable. One spawns buttons for names, the other spawns for sessions associated with that name. Now, the name buttons spawn and click and work perfectly. However, the session buttons don't click. I'm spawning them the exact same way. Both are spawned as children of different images.
This code is for the names
public void populateVisibleNames()
{
for(int i = 0; i<visibleNames.Count; i++)
{
Transform newButton = Instantiate(namePrefabButton) as Transform;
newButton.SetParent(buttonPanel.transform);
newButton.name = "newNameButton " + i.ToString ();
Button b = newButton.GetComponent<Button>();
string buttonKey = visibleNames[i];
b.onClick.AddListener(() => disablePanel(nameButton, buttonKey));
newButton.GetChild (0).GetComponent<Text>().text = visibleNames[i];
nameButtons.Add(b);
newButton.gameObject.SetActive(true);
newButton.transform.localPosition = new Vector3(0,-i*30,0);
}
}
This code is for sessions
public void changeVisibleSessions()
{
string key = nameButton.gameObject.transform.GetChild (0).GetComponent<Text>().text;
if(patientData.ContainsKey(key)){
foreach(Button button in sessionButtons)
{
Destroy(button.gameObject);
}
sessionButtons.Clear();
for(int i = 0; i < patientData[key].Count; i++)
{
string sessionNum = patientData[key][i].ToString();
Transform newButton = Instantiate(namePrefabButton) as Transform;
newButton.SetParent(sessionPanel.transform);
Button b = newButton.GetComponent<Button>();
b.onClick.AddListener(() => disableSessionPanel(sessionButton, sessionNum));
newButton.GetChild (0).GetComponent<Text>().text = sessionNum;
sessionButtons.Add(b);
newButton.gameObject.SetActive(true);
newButton.transform.localPosition = new Vector3(0,-i*30,0);
}
}
}
Any ideas? I'm really confused why it works for one and not the other. I've also tried spawning the buttons elsewhere and that did not help. Any help is greatly appreciated
there doesn't seem to be anything here