This question was
closed Jan 17, 2016 at 11:58 AM by
hexagonius for the following reason:
User answered question himself
instancing several buttons with different text
Still pretty new to Unity makeing a turnbased game and I'm trying to spawn my ability menus which is a series of vertical buttons based on how many abilities that have been unlocked. I can't quite figure out why this isn't working.
public void ActionMenuActivate (int selection) {
int abilitiesUlck = player.GetComponent<ShipController> ().crewMan[selection].GetComponent<CrewValues> ().abilitiesUnlocked;
Vector3 targetPlace = new Vector3 (220, 110, 0);
for (var i =0;i<abilitiesUlck;i++)
{
string abilityName = player.GetComponent<ShipController> ().crewMan[selection].GetComponent<CrewValues> ().abilities[i];
GameObject button =Instantiate (actionButton);
button.transform.SetParent (orderMenu.transform, false);
button.transform.localPosition = targetPlace;
GameObject btnText = GameObject.Find ("AbilityText");
Debug.Log(abilityName);
btnText.GetComponent<Text> ().text = abilityName;
targetPlace.y -=20f;
button.gameObject.SetActive (true);
}
}
The buttons spawn properly but only the first button is labeled with anything at all and its the last ability name. I'm pretty sure the problem is GameObject.Find("AbilityText") but I can't figure out a better way to look up the text I want to set. I've been trying to use button.transform.GetChild(0) but its not working out and I'm stumped
Comment