So I am working on a 3D/2D game, not sure how to really describe the ‘type’, in a sence sorta like a Grid game with a top down camera, but where you can rotate the camera in 3D space, and all objects are 3D but in a 2D grid/tile set layout.
What I am working on atm is a level loader, map creator.
All seems to work well unless I try to make a really large map, then it either hangs and acts like its going to crash, ie window says not responding but can sometimes finish, or not responding terms to windows closing the app. On small loads its quick and works fine so not sure if its due to a limit to how many things can be Instantiated at a time or if I just need to add a small delay or something to allow it to not take full control on a single function. Below is the code, you can run it just fine, but if i set the map size to like 1k x 1k, it seems to get more unstable, so was thinking a delay would work to allow it to not crash out but not sure how to add the waitforseconds part yet, or if there is just a limit to how many objects the engine itself can accualy handle to spawn in.
Any ideas?
using UnityEngine;
using System.Collections;
public class SpawnBlocks : MonoBehaviour
{
public GameObject RockBlock;
public GameObject DirtBlock;
public GameObject EmptyBlock;
public uint worldHeight = 100;
public uint worldWidth = 100;
void Start ()
{
CreateWorld();
}
void CreateWorld()
{
for(int x = 0; x < worldHeight; x++)
{
for(int z = 0; z < worldHeight; z++)
{
GameObject go = Instantiate(RockBlock);
string temp = "BlockAt: " + x + " x " + z;
go.name = temp;
go.transform.position = new Vector3(this.transform.position.x + x*10, this.transform.position.y, this.transform.position.z + z*10);
}
}
}
}