- Home /
Question by
iphonestatus · Oct 12, 2018 at 11:56 AM ·
unity 5uiinstantiateuiview
How to make a tournament bracket ?
I have a custom input that i would have to give to a function that will create a tournament bracket for me, for example if i have 8 players it would create a bracket for me to show the results of the tournament. please check the image below to show the 8 person bracket.
Please refer to the code i have so far to do so, I have generated the general algo for it but i want to link the created gameobjects and also manage the spacing between the hierarchy
public int TotalNoOfPlayers=8;
public GameObject TournamentEmptyPlayerPrefab,TournamentPlayerPrefab, MarkerGrid,RowHolderPrefab, TournamentSVParent;
IEnumerator DisplayTournamentEnum(){
string abc = "";
int raiseTo; raiseTo= int.Parse(Mathf.Log (TotalNoOfPlayers, 2).ToString());
int lengthOfTOurnament; lengthOfTOurnament = 2 * raiseTo + 1;
Debug.Log (raiseTo + "\t" + lengthOfTOurnament);
Debug.Log (Mathf.CeilToInt(TotalNoOfPlayers/(2f*4)));
CanvasManager.Instance.StartLoader ();
for (int i = 1; i <=(lengthOfTOurnament)/2; i++) {
GameObject RowParent = Instantiate (RowHolderPrefab, TournamentSVParent.transform);
for (int j = 1; j <= Mathf.CeilToInt (TotalNoOfPlayers / Mathf.Pow(2,i)); j++) {
for (int k = 1; k <= i; k++) {
GameObject childEmptyGO = Instantiate (TournamentEmptyPlayerPrefab, RowParent.transform);
}
GameObject childGO = Instantiate (TournamentPlayerPrefab, RowParent.transform);
}
}
for (int i = (lengthOfTOurnament/2)-1; i >=1; i--) {
GameObject RowParent = Instantiate (RowHolderPrefab, TournamentSVParent.transform);
for (int j = 1; j <= Mathf.CeilToInt(TotalNoOfPlayers/Mathf.Pow(2,i)); j++) {
for (int k = 1; k <= i; k++) {
GameObject childEmptyGO = Instantiate (TournamentEmptyPlayerPrefab, RowParent.transform);
}
GameObject childGO = Instantiate (TournamentPlayerPrefab, RowParent.transform);
}
}
Debug.Log (abc);
yield return null;
}
bracket.png
(66.9 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612180215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate problem with selected objects 0 Answers
Xbox Controller and Unity Buttons UI 0 Answers
Raycast from 2D canvas object to world space 1 Answer
Unity UI Position 2 Answers
how can i access multiple sprites using a single variable? 1 Answer