我有一個brainfart和似乎想法如何替換這個「while」爲可接受的模擬將使用相同的結果。我嘗試的每件事都會使這個函數產生不準確的結果(???),這讓我很生氣。用可接受的替代替換「while」語句
public void AllDecendantsList(Transform transform)
{
List<Transform> tempList = new List<Transform>();;
int CurrentTransformIndex = tempList.Count;
foreach (Transform t in transform)
{
if (condition)
{
//stuff
this.myDict.Add(t.gameObject, value);
}
tempList.Add(t);
}
while (CurrentTransformIndex < tempList.Count)
{
Transform currentTransform= tempList[CurrentTransformIndex++];
if (currentTransform.childCount > 0)
{
foreach (Transform t2 in currentTransform)
{
if (condition)
{
//stuff
this.myDict.Add(t2.gameObject, value);
}
tempList.Add(t2);
}
}
}
}
任何提示將不勝感激。
什麼是'childCounter'的目的,在你的程序?你初始化它,你更新它,你不讀它。你從未讀過的變量的功能是什麼?更一般地說:如果它沒有被破壞,那麼你爲什麼試圖修復它? –
爲什麼有一個叫做returnValue的變量永遠不會被返回?這段代碼似乎是故意難以理解的。 **首先讓您的代碼更易於理解**。 –