So I have a code that generates a list of buttons, one for each enemy on the field. Im trying to write an onclick function that searches the gameobjects/fighters on the field, and compares the names against the text of the button you pressed, and if they match, add them to a list. I would then make the attack to damage to all objects on that list. everything else but this is working thus far. also, as far as the debugs, the function does run, it just doesn't run the 'foreach' loop in the function. Code (CSharp): public void SelectTarget(Button attackChoie) { foreach (GameObject target in lists.combatants) { if (attackChoice.GetComponentInChildren<Text>(true).text == target.name) { attackTargetList.Add(target); Debug.Log("List ran"); Debug.Log(target.name); } else { Debug.Log("Else"); } } Debug.Log("Target Select Ran"); } } This is the function that instantiates the buttons, if that's at all helpful: Code (CSharp): public List <Button> DisplayTargets() { attackChoiceListOn = true; ColorBlock green = attackChoice.colors; green.normalColor = Color.green; ColorBlock red = attackChoice.colors; red.normalColor = Color.red; attackOrderPanel.SetActive(true); attackAlert.enabled = false; for (int t = 0; t < lists.combatants.Count;t++) { Button attackButton = Instantiate(attackChoice); attackButton.transform.SetParent(verticalList); attackButton.GetComponentInChildren<Text>().text = lists.combatants[t].name; if (lists.combatants[t].tag == "Player") { attackButton.colors = green; } else { attackButton.colors = red; } Debug.Log(lists.combatants[t].tag); attackChoiceList.Add(attackButton); } return attackChoiceList; } } I also tried making the SelectTarget function return a list, and then have an void function that runs the SelectTarget function, so I could run it as onClick, but this of course didn't work. I hope this is clear enough, I'm really stuck! if you need any more details or screenshots, Im glad to post.
How or where is SelectTarget actually called? If it is being called and you see a "Target Select Run" in your console, but none of the other debugs, then lists.combatants must be empty.