2016-11-22 33 views
0

在之前的文章中,我問過如何調試一個刻度問題:Debugging Scale如何防止規模變化?

修復問題後,似乎有另一個問題,我不明白。我試圖刪除我的按鈕列表並填充一個新的按鈕列表(刷新)。

我爆發了刪除按鈕然後將其添加回去的功能。我正在使用設置原始按鈕的相同腳本,MakeAllButtons

這是個什麼樣子,當我填充按鈕 enter image description here

列表當我刪除按鈕的列表,並添加後退按鈕列表中它看起來像這樣等。縮小到0.3。

enter image description here

如果我添加按鈕(只需點擊Add第二次)的另一個列表,它看起來像這樣: enter image description here

的按鈕列表的規模是回哪裏的假設是。

添加按鈕代碼:

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

回答

0

看來,當我刪除對象時,它正在存儲上一次加載的比例。

所以我強迫新的對象有我想要的規模,它解決了問題。

 GameObject newButton = buttonObjectPool.GetObject(); 
     newButton.transform.localScale = new Vector3(1, 1, 1); 
     newButton.transform.SetParent(positionPanel, false);