0
在之前的文章中,我问过如何调试一个刻度问题:Debugging Scale如何防止规模变化?
修复问题后,似乎有另一个问题,我不明白。我试图删除我的按钮列表并填充一个新的按钮列表(刷新)。
我爆发了删除按钮然后将其添加回去的功能。我正在使用设置原始按钮的相同脚本,MakeAllButtons
。
列表当我删除按钮的列表,并添加后退按钮列表中它看起来像这样等。缩小到0.3。
如果我添加按钮(只需点击Add
第二次)的另一个列表,它看起来像这样:
的按钮列表的规模是回哪里的假设是。
添加按钮代码:
public void MakeAllButtons()
{
for (int i = 0; i < positionList.Count; i++)
{
Position position = positionList[i];
PlayerPrefs.SetInt("PositionUnlocked" + i, position.unlocked); //sets if the item is unlocked
GameObject newButton = buttonObjectPool.GetObject();
newButton.transform.SetParent(positionPanel, false); //this was the problem originally
ButtonDetails buttonDetails = newButton.GetComponent<ButtonDetails>();
buttonDetails.SetupPosition(position, this);
}
}
删除按钮CODE
public void RemoveButtons()
{
while (positionPanel.childCount > 0)
{
GameObject toRemove = positionPanel.transform.GetChild(0).gameObject;
buttonObjectPool.ReturnObject(toRemove);
}
}
创建newButton
后,不知何故newButton.localScale
被设置为3,但只适用于第一次运行通过的码。