I am loving this course and something has clicked which I think its the way CodeMonkey teaches.
Anyway I am working on my buttons and have a basic question about this piece of code
var unitActions = currentUnit.GetComponents<BaseAction>(); List<Transform> buttonList = new List<Transform>(); foreach (var action in unitActions) { var myButton = Instantiate(myButtonPrefab, transform); myButton.GetComponent<ButtonBehaviour>().SetBaseAction(action); myButton.GetComponentInChildren<TextMeshProUGUI>().text=action.GetActionName(); buttonList.Add(myButton); } buttonList[0].GetComponent<ButtonBehaviour>().HighlightButton(); transform.GetChild(0).GetComponent<ButtonBehaviour>().HighlightButton();
What it does is highlight the first button green by calling this…
buttonList[0].GetComponent<ButtonBehaviour>().HighlightButton();
but if I try to do it with the following instead it doesn’t work?
transform.GetChild(0).GetComponent<ButtonBehaviour>().HighlightButton();
Any ideas?