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,但只適用於第一次運行通過的碼。