C# ';固定的';Unity-延迟逐个删除Tilemap磁贴
我一直在尝试获取Tilemap的平铺,我可以使用我在另一个问题中发现的代码来获取它们:C# ';固定的';Unity-延迟逐个删除Tilemap磁贴,c#,unity3d,C#,Unity3d,我一直在尝试获取Tilemap的平铺,我可以使用我在另一个问题中发现的代码来获取它们: BoundsInt bounds = Lvl1.cellBounds; TileBase[] allTiles = Lvl1.GetTilesBlock(bounds); for (int x = 0; x < bounds.size.x; x++) { for (int y = 0; y < bounds.size.y; y++)
BoundsInt bounds = Lvl1.cellBounds;
TileBase[] allTiles = Lvl1.GetTilesBlock(bounds);
for (int x = 0; x < bounds.size.x; x++)
{
for (int y = 0; y < bounds.size.y; y++)
{
TileBase tile = allTiles[x + y * bounds.size.x];
if (tile != null)
{
Lvl1.SetTile(new Vector3Int(x, y, 0), null);
StartCoroutine(BreakDelay());
}
else
{
//Debug.Log("x:" + x + " y:" + y + " tile: (null)");
}
}
}
BoundsInt bounds=Lvl1.cellbunds;
TileBase[]allTiles=Lvl1.GetTilesBlock(边界);
for(int x=0;x
但是现在我想一个接一个地删除记录的每个磁贴,例如延迟为“0.1f”。我已经尝试了很多方法,但都没有达到我想要的效果,所以我放弃了,然后我会记得StackOverflock,现在我在这里试图寻求帮助,那么有人知道解决这个问题的方法吗
提前谢谢
这不是协同程序的工作方式
这将启动协同路由的执行(可以随时暂停),但不会暂停调用方的执行
如果希望当前代码等待,则需要将其设置为协同程序:
StartCoroutine(DeleteTiles());
...
private IEnumerator DeleteTiles() {
BoundsInt bounds = Lvl1.cellBounds;
TileBase[] allTiles = Lvl1.GetTilesBlock(bounds);
for (int x = 0; x < bounds.size.x; x++)
{
for (int y = 0; y < bounds.size.y; y++)
{
TileBase tile = allTiles[x + y * bounds.size.x];
if (tile != null)
{
Lvl1.SetTile(new Vector3Int(x, y, 0), null);
yield return new WaitForSeconds(1); //or however long
}
else
{
//Debug.Log("x:" + x + " y:" + y + " tile: (null)");
}
}
}
}
start例程(DeleteTiles());
...
私有IEnumerator DeleteTiles(){
BoundsInt bounds=Lvl1.cellBounds;
TileBase[]allTiles=Lvl1.GetTilesBlock(边界);
for(int x=0;x
好的,我发现地图没有在正确的位置删除,我会修复它并告诉你它是否有效!很高兴你修好了,因为我不知道。我刚刚复制了你的代码P
StartCoroutine(DeleteTiles());
...
private IEnumerator DeleteTiles() {
BoundsInt bounds = Lvl1.cellBounds;
TileBase[] allTiles = Lvl1.GetTilesBlock(bounds);
for (int x = 0; x < bounds.size.x; x++)
{
for (int y = 0; y < bounds.size.y; y++)
{
TileBase tile = allTiles[x + y * bounds.size.x];
if (tile != null)
{
Lvl1.SetTile(new Vector3Int(x, y, 0), null);
yield return new WaitForSeconds(1); //or however long
}
else
{
//Debug.Log("x:" + x + " y:" + y + " tile: (null)");
}
}
}
}