2016-11-22 74 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);