1 回答
TA贡献1817条经验 获得超14个赞
我强烈建议查看 Unity 的工作系统,但你的循环令人难以置信的混乱,不确定那里发生了什么......你似乎也太复杂了。所以这就是我将如何实例化一张 1000x1000 图块的地图,如果我必须实例化它们的话:
public int mapWidth = 30;
public int mapHeight = 30;
void fill()
{
// Doing this once at the beginning, so it isn't super expensive...
GameObject basePrefab = GameObject.Find("Dirt");
// Creating 1 Vector3 that we can just update the values on
Vector3 spawnPosition = Vector3.zero;
for(int x = 0; x < mapWidth; ++x)
{
// Update the spawn x Position
spawnPosition.x = x;
for(int y = mapHeight; y > 0; y--)
{
// Update the spawn y position
spawnPosition.y = y;
Instantiate(basePrefab, spawnPosition, Quaternion.identity);
}
}
}
如果你想阅读或查看类似系统的瓦片地图的对象池示例,这是我不久前写的一个答案应该给你它的精神:What is the fastest method to create and render large number of 2d Unity 中的精灵?
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报