//tells this button manager that the id was clicked. also resets state of every other button public void NotifyClicked(int id) { idselected = id; for (int i = 0; i < buttons.Count; i++) { TitleButtonScript tb = buttons[i].GetComponent <TitleButtonScript>(); try { if (tb.GetId() != id) { tb.SetUnclicked(); } } catch (System.Exception e) { Debug.LogError("Bad button scripts when trying to update button states"); } } }
//instantiates buttons void BuildButtons() { buttons = new List <GameObject>(); for (int i = 0; i < texts.Length; i++) { GameObject gb = Instantiate(buttontemplate); try { TitleButtonScript tb = gb.GetComponent <TitleButtonScript>(); tb.SetController(this, i); TMP_Squiggle sq = gb.GetComponent <TMP_Squiggle>(); sq.SetSource(texts[i]); gb.GetComponent <RectTransform>().SetParent(gameObject.GetComponent <RectTransform>(), false); //call to GetComponent may be replaceable by directly accessing transform. gb.GetComponent <RectTransform>().SetAsLastSibling(); //might be unnecessary buttons.Add(gb); } catch (System.Exception e) { Debug.LogError("Error when instantiating buttons"); } } }