I have this script here that generates buttons based on an array and a serialized grid transform
public void InitializeUI()
{
LevelItem[] levelItemsArray = LevelSystemManager.Instance.LevelData.levelItemArray;
for (int i = 0; i < levelItemsArray.Length; i++)
{
if (i % n == 0) // sets it to 15
{
LevelButtonScript levelButton = Instantiate(levelBtnPrefab, levelBtnGridHolder);
levelButton.SetLevelButton(levelItemsArray[i], i, i == LevelSystemManager.Instance.LevelData.lastUnlockedLevel);
var page = GameObject.FindObjectOfType<UI.Pagination.PagedRect>();
page.AddPageUsingTemplate();
}
}
}
Now what I'm trying to do is make that array instantiate a new page (calling the page.AddPageUsingTemplate()
function which is from another script) once for every 15 items of the array.
I have 75 levels and want to instantiate the buttons on a new game object which has a grid layout group, so it would be 15 buttons on each grid with 5 pages/grids in total.
I do indeed get 5 pages when I run this code, but since the transform is only set to the first one the buttons don't get placed on the other pages.
How can I place buttons after the first 15 on the following pages?
AddPageUsingTemplate
? Could you set upAddPageUsingTemplate
to return a reference to this grid object? \$\endgroup\$