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 關注
- 124 瀏覽
添加回答
舉報