我在下面的代码中遇到了问题。它的功能是建立一条路线,一个接一个。C#IEnumerator不可更改
currentLength = Random.Range(maxFloorLength - 2, maxFloorLength);
List<GameObject> tempList = new List<GameObject>();
for (int i = 0; i < currentLength; ++i)
{
foreach (GameObject g in pooledFloor)
{
if (!g.activeInHierarchy)
{
g.SetActive(true);
g.transform.position = startPoint + buildDirection * i;
g.transform.DOScaleY(5, 0.25f).Play();
lastFloorPositions.Add(g.transform.position);
tempList.Add(g);
break;
}
}
yield return new WaitForSeconds(0.05f);
}
虽然这正常工作,当我将其更改为:
currentLength = Random.Range(maxFloorLength - 2, maxFloorLength);
List<GameObject> tempList = new List<GameObject>();
for (int i = 0; i < currentLength; ++i)
{
foreach (GameObject g in pooledFloor)
{
if (!g.activeInHierarchy)
{
g.transform.position = startPoint + buildDirection * i;
lastFloorPositions.Add(g.transform.position);
tempList.Add(g);
break;
}
}
}
foreach (GameObject g in tempList)
{
g.SetActive(true);
g.transform.DOScaleY(5, 0.25f).Play();
yield return new WaitForSeconds(0.05f);
}
它是所有创造之路的一个部分(就是那个应该是tempList列表的末尾)。我想要的是该脚本将所有预制件添加到列表中,然后再与他们一起做其他事情,所以我可以在两者之间添加一些内容。我试图将其更改为void函数,并将这些代码作为ienumerator调用,更改循环类型等,但似乎没有任何工作,我不知道为什么它不起作用。我使用Debug.Log检查了它是否仍然发现超过1个预制,并且它确实存在,但它只激活并扩展其中的一个。我敢打赌,它的东西很明显,但我就是不能看到它:/
如何看起来:
那应该怎么看:
忘了提及 - IEnumerator内部的所有内容
不知道,但也许你可以/应该问这http://gamedev.stackexchange.com/? –
第一回合是嵌套的,第二回合不是。尝试: –
@Kuniq检查我的答案 –